1 parent
b818e7a4a9
commit
027a0d30ac
18 files changed
+608
-526
No files matched your search
@@ -388,6 +388,17 @@ namespace HandyControlDemo.Properties.Langs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to 关闭主窗口对话框.
|
||||||
|
/// </summary>
|
||||||
|
public static string CloseMainWindowDialog
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ResourceManager.GetString("CloseMainWindowDialog", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to 颜色拾取器.
|
/// Looks up a localized string similar to 颜色拾取器.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>水印</value>
|
<value>水印</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>关闭主窗口对话框</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -804,4 +804,7 @@
|
|||||||
<data name="Watermark" xml:space="preserve">
|
<data name="Watermark" xml:space="preserve">
|
||||||
<value>Watermark</value>
|
<value>Watermark</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="CloseMainWindowDialog" xml:space="preserve">
|
||||||
|
<value>Close main window dialog</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -13,8 +13,8 @@
|
|||||||
{
|
{
|
||||||
langDic[item] =
|
langDic[item] =
|
||||||
@$"/// <summary>
|
@$"/// <summary>
|
||||||
/// {string.Format(Lang.LangComment, Lang.ResourceManager.GetString(item, Lang.Culture))}
|
/// {string.Format(Lang.LangComment, Lang.ResourceManager.GetString(item, Lang.Culture))}
|
||||||
/// </summary>";
|
/// </summary>";
|
||||||
}
|
}
|
||||||
#>
|
#>
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@@ -23,62 +23,66 @@ using System.Windows;
|
|||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using HandyControl.Tools;
|
using HandyControl.Tools;
|
||||||
|
|
||||||
namespace HandyControlDemo.Properties.Langs
|
namespace HandyControlDemo.Properties.Langs;
|
||||||
|
|
||||||
|
public class LangProvider : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public class LangProvider : INotifyPropertyChanged
|
internal static LangProvider Instance { get; } = ResourceHelper.GetResource<LangProvider>("DemoLangs");
|
||||||
|
|
||||||
|
private static string CultureInfoStr;
|
||||||
|
|
||||||
|
public static CultureInfo Culture
|
||||||
{
|
{
|
||||||
internal static LangProvider Instance { get; } = ResourceHelper.GetResource<LangProvider>("DemoLangs");
|
get => Lang.Culture;
|
||||||
|
set
|
||||||
private static string CultureInfoStr;
|
|
||||||
|
|
||||||
public static CultureInfo Culture
|
|
||||||
{
|
{
|
||||||
get => Lang.Culture;
|
if (value == null) return;
|
||||||
set
|
if (Equals(CultureInfoStr, value.EnglishName)) return;
|
||||||
{
|
Lang.Culture = value;
|
||||||
if (value == null) return;
|
CultureInfoStr = value.EnglishName;
|
||||||
if (Equals(CultureInfoStr, value.EnglishName)) return;
|
|
||||||
Lang.Culture = value;
|
|
||||||
CultureInfoStr = value.EnglishName;
|
|
||||||
|
|
||||||
Instance.UpdateLangs();
|
Instance.UpdateLangs();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetLang(string key) => Lang.ResourceManager.GetString(key, Culture);
|
|
||||||
|
|
||||||
public static void SetLang(DependencyObject dependencyObject, DependencyProperty dependencyProperty, string key) =>
|
|
||||||
BindingOperations.SetBinding(dependencyObject, dependencyProperty, new Binding(key)
|
|
||||||
{
|
|
||||||
Source = Instance,
|
|
||||||
Mode = BindingMode.OneWay
|
|
||||||
});
|
|
||||||
|
|
||||||
private void UpdateLangs()
|
|
||||||
{
|
|
||||||
<#foreach(var item in propertyNameList){#>
|
|
||||||
OnPropertyChanged(nameof(<#=item#>));
|
|
||||||
<#}#>
|
|
||||||
}
|
|
||||||
|
|
||||||
<#foreach(var item in propertyNameList){#>
|
|
||||||
<#=langDic[item]#>
|
|
||||||
public string <#=item#> => Lang.<#=item#>;
|
|
||||||
|
|
||||||
<#}#>
|
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged(string propertyName) =>
|
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LangKeys
|
public static string GetLang(string key)
|
||||||
|
{
|
||||||
|
return Lang.ResourceManager.GetString(key, Culture);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetLang(DependencyObject dependencyObject, DependencyProperty dependencyProperty, string key)
|
||||||
|
{
|
||||||
|
BindingOperations.SetBinding(dependencyObject, dependencyProperty, new Binding(key)
|
||||||
|
{
|
||||||
|
Source = Instance,
|
||||||
|
Mode = BindingMode.OneWay
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateLangs()
|
||||||
{
|
{
|
||||||
<#foreach(var item in propertyNameList){#>
|
<#foreach(var item in propertyNameList){#>
|
||||||
<#=langDic[item]#>
|
OnPropertyChanged(nameof(<#=item#>));
|
||||||
public static string <#=item#> = nameof(<#=item#>);
|
|
||||||
|
|
||||||
<#}#>
|
<#}#>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<#foreach(var item in propertyNameList){#>
|
||||||
|
<#=langDic[item]#>
|
||||||
|
public string <#=item#> => Lang.<#=item#>;
|
||||||
|
|
||||||
|
<#}#>
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
protected virtual void OnPropertyChanged(string propertyName) =>
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LangKeys
|
||||||
|
{
|
||||||
|
<#foreach(var item in propertyNameList){#>
|
||||||
|
<#=langDic[item]#>
|
||||||
|
public static string <#=item#> = nameof(<#=item#>);
|
||||||
|
|
||||||
|
<#}#>
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Windows;
|
||||||
using System.Windows;
|
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
using GalaSoft.MvvmLight.Command;
|
using GalaSoft.MvvmLight.Command;
|
||||||
#if !NET40
|
#if !NET40
|
||||||
@@ -81,4 +80,6 @@ public class DialogDemoViewModel : ViewModelBase
|
|||||||
}.Show());
|
}.Show());
|
||||||
|
|
||||||
public RelayCommand<string> ShowWithTokenCmd => new(token => Dialog.Show(new TextDialog(), token));
|
public RelayCommand<string> ShowWithTokenCmd => new(token => Dialog.Show(new TextDialog(), token));
|
||||||
|
|
||||||
|
public RelayCommand<string> CloseMainWindowDialogCmd => new(Dialog.Close);
|
||||||
}
|
}
|
||||||
@@ -10,9 +10,10 @@
|
|||||||
Width="800"
|
Width="800"
|
||||||
Height="500">
|
Height="500">
|
||||||
<hc:TransitioningContentControl>
|
<hc:TransitioningContentControl>
|
||||||
<StackPanel Margin="32" VerticalAlignment="Center">
|
<hc:UniformSpacingPanel Margin="32" VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="10" Orientation="Vertical">
|
||||||
<Button Content="{ex:Lang Key={x:Static langs:LangKeys.ShowInCurrentWindow}}" Command="{Binding ShowWithTokenCmd}" CommandParameter="{Binding DialogToken,RelativeSource={RelativeSource AncestorType=Window}}"/>
|
<Button Content="{ex:Lang Key={x:Static langs:LangKeys.ShowInCurrentWindow}}" Command="{Binding ShowWithTokenCmd}" CommandParameter="{Binding DialogToken,RelativeSource={RelativeSource AncestorType=Window}}"/>
|
||||||
<Button Margin="0,10,0,0" Content="{ex:Lang Key={x:Static langs:LangKeys.ShowInMainWindow}}" Command="{Binding ShowWithTokenCmd}" CommandParameter="{x:Static data:MessageToken.MainWindow}"/>
|
<Button Content="{ex:Lang Key={x:Static langs:LangKeys.ShowInMainWindow}}" Command="{Binding ShowWithTokenCmd}" CommandParameter="{x:Static data:MessageToken.MainWindow}"/>
|
||||||
</StackPanel>
|
<Button Content="{ex:Lang Key={x:Static langs:LangKeys.CloseMainWindowDialog}}" Command="{Binding CloseMainWindowDialogCmd}" CommandParameter="{x:Static data:MessageToken.MainWindow}" />
|
||||||
|
</hc:UniformSpacingPanel>
|
||||||
</hc:TransitioningContentControl>
|
</hc:TransitioningContentControl>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -20,7 +20,8 @@ public class Dialog : ContentControl
|
|||||||
private Border _backElement;
|
private Border _backElement;
|
||||||
private AdornerContainer _container;
|
private AdornerContainer _container;
|
||||||
|
|
||||||
private static readonly Dictionary<string, FrameworkElement> ContainerDic = new();
|
private static readonly Dictionary<string, FrameworkElement> ContainerDict = new();
|
||||||
|
private static readonly Dictionary<string, Dialog> DialogDict = new();
|
||||||
|
|
||||||
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
|
||||||
nameof(IsClosed), typeof(bool), typeof(Dialog), new PropertyMetadata(ValueBoxes.FalseBox));
|
nameof(IsClosed), typeof(bool), typeof(Dialog), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||||
@@ -81,18 +82,18 @@ public class Dialog : ContentControl
|
|||||||
public static void Register(string token, FrameworkElement element)
|
public static void Register(string token, FrameworkElement element)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(token) || element == null) return;
|
if (string.IsNullOrEmpty(token) || element == null) return;
|
||||||
ContainerDic[token] = element;
|
ContainerDict[token] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Unregister(string token, FrameworkElement element)
|
public static void Unregister(string token, FrameworkElement element)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(token) || element == null) return;
|
if (string.IsNullOrEmpty(token) || element == null) return;
|
||||||
|
|
||||||
if (ContainerDic.ContainsKey(token))
|
if (ContainerDict.ContainsKey(token))
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(ContainerDic[token], element))
|
if (ReferenceEquals(ContainerDict[token], element))
|
||||||
{
|
{
|
||||||
ContainerDic.Remove(token);
|
ContainerDict.Remove(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,10 +101,10 @@ public class Dialog : ContentControl
|
|||||||
public static void Unregister(FrameworkElement element)
|
public static void Unregister(FrameworkElement element)
|
||||||
{
|
{
|
||||||
if (element == null) return;
|
if (element == null) return;
|
||||||
var first = ContainerDic.FirstOrDefault(item => ReferenceEquals(element, item.Value));
|
var first = ContainerDict.FirstOrDefault(item => ReferenceEquals(element, item.Value));
|
||||||
if (!string.IsNullOrEmpty(first.Key))
|
if (!string.IsNullOrEmpty(first.Key))
|
||||||
{
|
{
|
||||||
ContainerDic.Remove(first.Key);
|
ContainerDict.Remove(first.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,9 +112,9 @@ public class Dialog : ContentControl
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(token)) return;
|
if (string.IsNullOrEmpty(token)) return;
|
||||||
|
|
||||||
if (ContainerDic.ContainsKey(token))
|
if (ContainerDict.ContainsKey(token))
|
||||||
{
|
{
|
||||||
ContainerDic.Remove(token);
|
ContainerDict.Remove(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,8 +129,8 @@ public class Dialog : ContentControl
|
|||||||
};
|
};
|
||||||
|
|
||||||
FrameworkElement element;
|
FrameworkElement element;
|
||||||
|
|
||||||
AdornerDecorator decorator;
|
AdornerDecorator decorator;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(token))
|
if (string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
element = WindowHelper.GetActiveWindow();
|
element = WindowHelper.GetActiveWindow();
|
||||||
@@ -137,7 +138,9 @@ public class Dialog : ContentControl
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ContainerDic.TryGetValue(token, out element);
|
Close(token);
|
||||||
|
DialogDict[token] = dialog;
|
||||||
|
ContainerDict.TryGetValue(token, out element);
|
||||||
decorator = element is System.Windows.Window ?
|
decorator = element is System.Windows.Window ?
|
||||||
VisualHelper.GetChild<AdornerDecorator>(element) :
|
VisualHelper.GetChild<AdornerDecorator>(element) :
|
||||||
VisualHelper.GetChild<DialogContainer>(element);
|
VisualHelper.GetChild<DialogContainer>(element);
|
||||||
@@ -149,6 +152,7 @@ public class Dialog : ContentControl
|
|||||||
{
|
{
|
||||||
decorator.Child.IsEnabled = false;
|
decorator.Child.IsEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var layer = decorator.AdornerLayer;
|
var layer = decorator.AdornerLayer;
|
||||||
if (layer != null)
|
if (layer != null)
|
||||||
{
|
{
|
||||||
@@ -165,15 +169,24 @@ public class Dialog : ContentControl
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Close(string token)
|
||||||
|
{
|
||||||
|
if (DialogDict.TryGetValue(token, out Dialog dialog))
|
||||||
|
{
|
||||||
|
dialog.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_token))
|
if (string.IsNullOrEmpty(_token))
|
||||||
{
|
{
|
||||||
Close(WindowHelper.GetActiveWindow());
|
Close(WindowHelper.GetActiveWindow());
|
||||||
}
|
}
|
||||||
else if (ContainerDic.TryGetValue(_token, out var element))
|
else if (ContainerDict.TryGetValue(_token, out var element))
|
||||||
{
|
{
|
||||||
Close(element);
|
Close(element);
|
||||||
|
DialogDict.Remove(_token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user