17 files changed
+220
-11
No files matched your search
@@ -164,5 +164,9 @@
|
||||
|
||||
public static readonly string GrowlDemoPanel = nameof(GrowlDemoPanel);
|
||||
|
||||
public static readonly string DialogDemoWindow = nameof(DialogDemoWindow);
|
||||
|
||||
public static readonly string MainWindow = nameof(MainWindow);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,9 @@ var messageList = new List<string>
|
||||
"ContributorsView",
|
||||
"ClearLeftSelected",
|
||||
"SendChatMessage",
|
||||
"GrowlDemoPanel"
|
||||
"GrowlDemoPanel",
|
||||
"DialogDemoWindow",
|
||||
"MainWindow"
|
||||
};
|
||||
#>
|
||||
namespace HandyControlDemo.Data
|
||||
|
||||
@@ -298,6 +298,9 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Window\CustomNonClientAreaWindow.xaml.cs">
|
||||
<DependentUpon>CustomNonClientAreaWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Window\DialogDemoWindow.xaml.cs">
|
||||
<DependentUpon>DialogDemoWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Window\GrowlDemoWindow.xaml.cs">
|
||||
<DependentUpon>GrowlDemoWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -682,6 +685,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Window\DialogDemoWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Window\GrowlDemoWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
|
||||
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
|
||||
xmlns:data="clr-namespace:HandyControlDemo.Data"
|
||||
mc:Ignorable="d"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#262e2f"
|
||||
@@ -19,6 +20,7 @@
|
||||
ResizeMode="CanResizeWithGrip"
|
||||
Name="MyWindow"
|
||||
DataContext="{Binding Main,Source={StaticResource Locator}}"
|
||||
controls:Dialog.Token="{x:Static data:MessageToken.MainWindow}"
|
||||
d:DesignHeight="800"
|
||||
d:DesignWidth="1400">
|
||||
<controls:Window.NonClientAreaContent>
|
||||
|
||||
@@ -429,6 +429,15 @@ namespace HandyControlDemo.Properties.Langs {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 对话框示例 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string DialogDemo {
|
||||
get {
|
||||
return ResourceManager.GetString("DialogDemo", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 在这里拖拽 的本地化字符串。
|
||||
/// </summary>
|
||||
@@ -1122,6 +1131,24 @@ namespace HandyControlDemo.Properties.Langs {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 在当前窗口显示 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string ShowInCurrentWindow {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInCurrentWindow", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 在主窗口显示 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string ShowInMainWindow {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInMainWindow", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 显示行号 的本地化字符串。
|
||||
/// </summary>
|
||||
|
||||
@@ -567,4 +567,13 @@
|
||||
<data name="RepeatButton" xml:space="preserve">
|
||||
<value>RepeatButton</value>
|
||||
</data>
|
||||
<data name="DialogDemo" xml:space="preserve">
|
||||
<value>Dialog demo</value>
|
||||
</data>
|
||||
<data name="ShowInCurrentWindow" xml:space="preserve">
|
||||
<value>Show in the current window</value>
|
||||
</data>
|
||||
<data name="ShowInMainWindow" xml:space="preserve">
|
||||
<value>Show in the main window</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -567,4 +567,13 @@
|
||||
<data name="RepeatButton" xml:space="preserve">
|
||||
<value>重复按钮</value>
|
||||
</data>
|
||||
<data name="DialogDemo" xml:space="preserve">
|
||||
<value>对话框示例</value>
|
||||
</data>
|
||||
<data name="ShowInCurrentWindow" xml:space="preserve">
|
||||
<value>在当前窗口显示</value>
|
||||
</data>
|
||||
<data name="ShowInMainWindow" xml:space="preserve">
|
||||
<value>在主窗口显示</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -11,6 +11,7 @@
|
||||
<Button Content="{x:Static langs:Lang.TextDialog}" Command="{Binding ShowTextCmd}" />
|
||||
<TextBox Margin="0,32,0,0" Text="{Binding DialogResult,UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource TextBoxExtend}" controls:InfoElement.Placeholder="{x:Static langs:Lang.PleaseInput}"/>
|
||||
<Button Margin="0,10,0,0" Content="{x:Static langs:Lang.InteractiveDialog}" Command="{Binding ShowInteractiveDialogCmd}"/>
|
||||
<Button Margin="0,32,0,0" Content="{x:Static langs:Lang.NewWindow}" Command="{Binding NewWindowCmd}"/>
|
||||
</StackPanel>
|
||||
</controls:TransitioningContentControl>
|
||||
</UserControl>
|
||||
@@ -11,7 +11,7 @@ namespace HandyControlDemo.ViewModel.Basic
|
||||
{
|
||||
public class InteractiveDialogViewModel : ViewModelBase, IDialogResultable<string>
|
||||
{
|
||||
public Action CloseAction { get; set; }
|
||||
public Action<string> CloseAction { get; set; }
|
||||
|
||||
private string _result;
|
||||
|
||||
@@ -37,6 +37,6 @@ namespace HandyControlDemo.ViewModel.Basic
|
||||
#endif
|
||||
}
|
||||
|
||||
public RelayCommand CloseCmd => new Lazy<RelayCommand>(() => new RelayCommand(() => CloseAction?.Invoke())).Value;
|
||||
public RelayCommand CloseCmd => new Lazy<RelayCommand>(() => new RelayCommand(() => CloseAction?.Invoke(""))).Value;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using GalaSoft.MvvmLight;
|
||||
#if netle40
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
@@ -11,6 +12,7 @@ using HandyControl.Tools.Extension;
|
||||
using HandyControlDemo.UserControl;
|
||||
using HandyControlDemo.UserControl.Basic;
|
||||
using HandyControlDemo.ViewModel.Basic;
|
||||
using HandyControlDemo.Window;
|
||||
|
||||
namespace HandyControlDemo.ViewModel
|
||||
{
|
||||
@@ -57,5 +59,14 @@ namespace HandyControlDemo.ViewModel
|
||||
.GetResultAsync<string>();
|
||||
}
|
||||
#endif
|
||||
|
||||
public RelayCommand NewWindowCmd => new Lazy<RelayCommand>(() =>
|
||||
new RelayCommand(() => new DialogDemoWindow
|
||||
{
|
||||
Owner = Application.Current.MainWindow
|
||||
}.Show())).Value;
|
||||
|
||||
public RelayCommand<string> ShowWithTokenCmd => new Lazy<RelayCommand<string>>(() =>
|
||||
new RelayCommand<string>(token => Dialog.Show(new TextDialog(), token))).Value;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
#if netle40
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
#else
|
||||
@@ -65,6 +66,9 @@ namespace HandyControlDemo.ViewModel
|
||||
new RelayCommand(() => Growl.Clear())).Value;
|
||||
|
||||
public RelayCommand NewWindowCmd => new Lazy<RelayCommand>(() =>
|
||||
new RelayCommand(() => new GrowlDemoWindow().Show())).Value;
|
||||
new RelayCommand(() => new GrowlDemoWindow
|
||||
{
|
||||
Owner = Application.Current.MainWindow
|
||||
}.Show())).Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Window x:Class="HandyControlDemo.Window.DialogDemoWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
|
||||
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
|
||||
xmlns:data="clr-namespace:HandyControlDemo.Data"
|
||||
controls:Dialog.Token="{x:Static data:MessageToken.DialogDemoWindow}"
|
||||
DataContext="{Binding DialogDemo,Source={StaticResource Locator}}"
|
||||
Title="{x:Static langs:Lang.DialogDemo}"
|
||||
Width="800"
|
||||
Height="500">
|
||||
<controls:TransitioningContentControl>
|
||||
<StackPanel Margin="32" VerticalAlignment="Center">
|
||||
<Button Content="{x:Static langs:Lang.ShowInCurrentWindow}" Command="{Binding ShowWithTokenCmd}" CommandParameter="{x:Static data:MessageToken.DialogDemoWindow}"/>
|
||||
<Button Margin="0,10,0,0" Content="{x:Static langs:Lang.ShowInMainWindow}" Command="{Binding ShowWithTokenCmd}" CommandParameter="{x:Static data:MessageToken.MainWindow}"/>
|
||||
</StackPanel>
|
||||
</controls:TransitioningContentControl>
|
||||
</Window>
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace HandyControlDemo.Window
|
||||
{
|
||||
public partial class DialogDemoWindow
|
||||
{
|
||||
public DialogDemoWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
@@ -12,6 +14,8 @@ namespace HandyControl.Controls
|
||||
{
|
||||
private Adorner _container;
|
||||
|
||||
private static readonly Dictionary<string, System.Windows.Window> WindowDic = new Dictionary<string, System.Windows.Window>();
|
||||
|
||||
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
|
||||
"IsClosed", typeof(bool), typeof(Dialog), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
@@ -21,21 +25,94 @@ namespace HandyControl.Controls
|
||||
internal set => SetValue(IsClosedProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TokenProperty = DependencyProperty.RegisterAttached(
|
||||
"Token", typeof(string), typeof(Dialog), new PropertyMetadata(default(string), OnTokenChanged));
|
||||
|
||||
private static void OnTokenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is System.Windows.Window window)
|
||||
{
|
||||
if (e.NewValue == null)
|
||||
{
|
||||
Unregister(window);
|
||||
}
|
||||
else
|
||||
{
|
||||
Register(e.NewValue.ToString(), window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetToken(DependencyObject element, string value)
|
||||
=> element.SetValue(TokenProperty, value);
|
||||
|
||||
public static string GetToken(DependencyObject element)
|
||||
=> (string) element.GetValue(TokenProperty);
|
||||
|
||||
public Dialog()
|
||||
{
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => Close()));
|
||||
}
|
||||
|
||||
public static Dialog Show<T>() where T : new() => Show(new T());
|
||||
public static void Register(string token, System.Windows.Window window)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token) || window == null) return;
|
||||
WindowDic[token] = window;
|
||||
}
|
||||
|
||||
public static Dialog Show(object content)
|
||||
public static void Unregister(string token, System.Windows.Window window)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token) || window == null) return;
|
||||
|
||||
if (WindowDic.ContainsKey(token))
|
||||
{
|
||||
if (ReferenceEquals(WindowDic[token], window))
|
||||
{
|
||||
WindowDic.Remove(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Unregister(System.Windows.Window window)
|
||||
{
|
||||
if (window == null) return;
|
||||
var first = WindowDic.FirstOrDefault(item => ReferenceEquals(window, item.Value));
|
||||
if (!string.IsNullOrEmpty(first.Key))
|
||||
{
|
||||
WindowDic.Remove(first.Key);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Unregister(string token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token)) return;
|
||||
|
||||
if (WindowDic.ContainsKey(token))
|
||||
{
|
||||
WindowDic.Remove(token);
|
||||
}
|
||||
}
|
||||
|
||||
public static Dialog Show<T>(string token = "") where T : new() => Show(new T(), token);
|
||||
|
||||
public static Dialog Show(object content, string token = "")
|
||||
{
|
||||
var dialog = new Dialog
|
||||
{
|
||||
Content = content
|
||||
};
|
||||
|
||||
var window = VisualHelper.GetActiveWindow();
|
||||
System.Windows.Window window;
|
||||
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
window = VisualHelper.GetActiveWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowDic.TryGetValue(token, out window);
|
||||
}
|
||||
|
||||
if (window != null)
|
||||
{
|
||||
var decorator = VisualHelper.GetChild<AdornerDecorator>(window);
|
||||
@@ -62,9 +139,23 @@ namespace HandyControl.Controls
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
public void Close(string token = "")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
if (WindowDic.TryGetValue(token, out var window))
|
||||
{
|
||||
Close(window);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Close(VisualHelper.GetActiveWindow());
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(System.Windows.Window window)
|
||||
{
|
||||
var window = VisualHelper.GetActiveWindow();
|
||||
if (window != null)
|
||||
{
|
||||
var decorator = VisualHelper.GetChild<AdornerDecorator>(window);
|
||||
|
||||
@@ -98,6 +98,19 @@ namespace HandyControl.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public static void Unregister(string token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token)) return;
|
||||
|
||||
if (PanelDic.ContainsKey(token))
|
||||
{
|
||||
var panel = PanelDic[token];
|
||||
PanelDic.Remove(token);
|
||||
panel.ContextMenu = null;
|
||||
panel.SetCurrentValue(PanelElement.FluidMoveBehaviorProperty, DependencyProperty.UnsetValue);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style x:Key="DatePickerTextBoxStyle" TargetType="DatePickerTextBox">
|
||||
<Setter Property="Foreground" Value="{Binding Foreground,RelativeSource={RelativeSource AncestorType=DatePicker}}"/>
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace HandyControl.Tools.Extension
|
||||
{
|
||||
T Result { get; set; }
|
||||
|
||||
Action CloseAction { get; set; }
|
||||
Action<string> CloseAction { get; set; }
|
||||
}
|
||||
|
||||
public static class DialogExtension
|
||||
|
||||
Reference in new issue
Block a user