add EnumDataProvider

This commit is contained in:
NaBian 2020-04-21 00:32:11 +08:00
parent 665ee3866e
commit a4e44b75d8
24 changed files with 2480 additions and 82 deletions

View File

@ -46,11 +46,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>MessageToken.tt</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangDecorator.cs">
<Link>Properties\Langs\LangDecorator.cs</Link>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangProvider.cs">
<Link>Properties\Langs\LangProvider.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>LangDecorator.tt</DependentUpon>
<DependentUpon>LangProvider.tt</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\Lang.Designer.cs">
<Link>Properties\Langs\Lang.Designer.cs</Link>
@ -523,10 +523,10 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MessageToken.cs</LastGenOutput>
</Content>
<Content Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangDecorator.tt">
<Link>Properties\Langs\LangDecorator.tt</Link>
<Content Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangProvider.tt">
<Link>Properties\Langs\LangProvider.tt</Link>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>LangDecorator.cs</LastGenOutput>
<LastGenOutput>LangProvider.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup>

View File

@ -42,11 +42,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>Lang.resx</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangDecorator.cs">
<Link>Properties\Langs\LangDecorator.cs</Link>
<Compile Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangProvider.cs">
<Link>Properties\Langs\LangProvider.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>LangDecorator.tt</DependentUpon>
<DependentUpon>LangProvider.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -72,10 +72,10 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangDecorator.tt">
<Link>Properties\Langs\LangDecorator.tt</Link>
<Content Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangProvider.tt">
<Link>Properties\Langs\LangProvider.tt</Link>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>LangDecorator.cs</LastGenOutput>
<LastGenOutput>LangProvider.cs</LastGenOutput>
</Content>
</ItemGroup>
<Import Project="..\..\Shared\HandyControl_Shared\HandyControl_Shared.projitems" Label="Shared" />

View File

@ -75,11 +75,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>MessageToken.tt</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangDecorator.cs">
<Link>Properties\Langs\LangDecorator.cs</Link>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangProvider.cs">
<Link>Properties\Langs\LangProvider.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>LangDecorator.tt</DependentUpon>
<DependentUpon>LangProvider.tt</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
@ -452,10 +452,10 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MessageToken.cs</LastGenOutput>
</Content>
<Content Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangDecorator.tt">
<Link>Properties\Langs\LangDecorator.tt</Link>
<Content Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangProvider.tt">
<Link>Properties\Langs\LangProvider.tt</Link>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>LangDecorator.cs</LastGenOutput>
<LastGenOutput>LangProvider.cs</LastGenOutput>
</Content>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\Effects_16x.png">
<Link>Resources\Img\LeftMainContent\Effects_16x.png</Link>

View File

@ -47,11 +47,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>Lang.resx</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangDecorator.cs">
<Link>Properties\Langs\LangDecorator.cs</Link>
<Compile Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangProvider.cs">
<Link>Properties\Langs\LangProvider.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>LangDecorator.tt</DependentUpon>
<DependentUpon>LangProvider.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -113,10 +113,10 @@
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Lang.Designer.cs</LastGenOutput>
</EmbeddedResource>
<Content Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangDecorator.tt">
<Link>Properties\Langs\LangDecorator.tt</Link>
<Content Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangProvider.tt">
<Link>Properties\Langs\LangProvider.tt</Link>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>LangDecorator.cs</LastGenOutput>
<LastGenOutput>LangProvider.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup>

View File

@ -155,11 +155,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>MessageToken.tt</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangDecorator.cs">
<Link>Properties\Langs\LangDecorator.cs</Link>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangProvider.cs">
<Link>Properties\Langs\LangProvider.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>LangDecorator.tt</DependentUpon>
<DependentUpon>LangProvider.tt</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
@ -513,10 +513,10 @@
</Resource>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangDecorator.tt">
<Link>Properties\Langs\LangDecorator.tt</Link>
<Content Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\LangProvider.tt">
<Link>Properties\Langs\LangProvider.tt</Link>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>LangDecorator.cs</LastGenOutput>
<LastGenOutput>LangProvider.cs</LastGenOutput>
</Content>
<Content Include="..\..\Shared\HandyControlDemo_Shared\Data\MessageToken.tt">
<Link>Data\MessageToken.tt</Link>

View File

@ -122,11 +122,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>Lang.resx</DependentUpon>
</Compile>
<Compile Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangDecorator.cs">
<Link>Properties\Langs\LangDecorator.cs</Link>
<Compile Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangProvider.cs">
<Link>Properties\Langs\LangProvider.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>LangDecorator.tt</DependentUpon>
<DependentUpon>LangProvider.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -158,10 +158,10 @@
<LastGenOutput>Lang.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Content Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangDecorator.tt">
<Link>Properties\Langs\LangDecorator.tt</Link>
<Content Include="..\..\Shared\HandyControl_Shared\Properties\Langs\LangProvider.tt">
<Link>Properties\Langs\LangProvider.tt</Link>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>LangDecorator.cs</LastGenOutput>
<LastGenOutput>LangProvider.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup>

View File

@ -4,42 +4,32 @@
xmlns:viewModel="clr-namespace:HandyControlDemo.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d1P1="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:data="clr-namespace:HandyControlDemo.Data"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:resources="clr-namespace:HandyControlDemo.Resources"
d1P1:Ignorable="d"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<hc:Theme Name="HandyTheme"/>
<resources:DemoTheme Name="DemoTheme"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="Resources/Themes/SkinDefault.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
<ResourceDictionary Source="Resources/Themes/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<langs:LangDecorator x:Key="DemoLangs"/>
<langs:LangProvider x:Key="DemoLangs"/>
<viewModel:ViewModelLocator x:Key="Locator" d:IsDataSource="True"/>
<ObjectDataProvider x:Key="DemoTypes" MethodName="GetValues" ObjectType="sys:Enum">
<ObjectDataProvider.MethodParameters>
<x:Type Type="data:DemoType"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="ShowAnimations" MethodName="GetValues" ObjectType="sys:Enum">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="hc:ShowAnimation"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="HatchStyles" MethodName="GetValues" ObjectType="sys:Enum">
<ObjectDataProvider.MethodParameters>
<x:Type Type="hc:HatchStyle"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<hc:EnumDataProvider x:Key="DemoTypes" Type="data:DemoType" MethodName=""/>
<hc:EnumDataProvider x:Key="ShowAnimations" Type="hc:ShowAnimation"/>
<hc:EnumDataProvider x:Key="HatchStyles" Type="hc:HatchStyle"/>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -88,8 +88,22 @@ namespace HandyControlDemo
internal void UpdateSkin(SkinType skin)
{
ResourceHelper.GetTheme("HandyTheme", Resources).Skin = skin;
ResourceHelper.GetTheme("DemoTheme", Resources).Skin = skin;
var skins0 = Resources.MergedDictionaries[0];
skins0.MergedDictionaries.Clear();
skins0.MergedDictionaries.Add(ResourceHelper.GetSkin(skin));
skins0.MergedDictionaries.Add(ResourceHelper.GetSkin(typeof(App).Assembly, "Resources/Themes", skin));
var skins1 = Resources.MergedDictionaries[1];
skins1.MergedDictionaries.Clear();
skins1.MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri("pack://application:,,,/HandyControl;component/Themes/Theme.xaml")
});
skins1.MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri("pack://application:,,,/HandyControlDemo;component/Resources/Themes/Theme.xaml")
});
Current.MainWindow?.OnApplyTemplate();
}

View File

@ -6,9 +6,9 @@ using HandyControl.Tools;
namespace HandyControlDemo.Properties.Langs
{
public class LangDecorator : INotifyPropertyChanged
public class LangProvider : INotifyPropertyChanged
{
internal static LangDecorator Instance => ResourceHelper.GetResource<LangDecorator>("DemoLangs");
internal static LangProvider Instance => ResourceHelper.GetResource<LangProvider>("DemoLangs");
private static string CultureInfoStr;

File diff suppressed because it is too large Load Diff

View File

@ -25,9 +25,9 @@ using HandyControl.Tools;
namespace HandyControlDemo.Properties.Langs
{
public class LangDecorator : INotifyPropertyChanged
public class LangProvider : INotifyPropertyChanged
{
internal static LangDecorator Instance => ResourceHelper.GetResource<LangDecorator>("DemoLangs");
internal static LangProvider Instance => ResourceHelper.GetResource<LangProvider>("DemoLangs");
private static string CultureInfoStr;

View File

@ -6,7 +6,7 @@ namespace HandyControlDemo.Tools.Extension
{
public LangExtension()
{
Source = LangDecorator.Instance;
Source = LangProvider.Instance;
}
}
}

View File

@ -16,7 +16,7 @@ namespace HandyControlDemo.UserControl
if (sender is TagPanel panel)
{
var tag = new Tag();
LangDecorator.SetLang(tag, ContentProperty, LangKeys.SubTitle);
LangProvider.SetLang(tag, ContentProperty, LangKeys.SubTitle);
panel.Children.Add(tag);
}
}

View File

@ -24,7 +24,7 @@ namespace HandyControlDemo.UserControl
PopupConfig.IsOpen = false;
if (tag.Equals(GlobalData.Config.Lang)) return;
ConfigHelper.Instance.SetLang(tag);
LangDecorator.Culture = new CultureInfo(tag);
LangProvider.Culture = new CultureInfo(tag);
Messenger.Default.Send<object>(null, "LangUpdated");
GlobalData.Config.Lang = tag;

View File

@ -60,7 +60,7 @@ namespace HandyControlDemo.ViewModel
Messenger.Default.Register<object>(this, MessageToken.LangUpdated, obj =>
{
if (DemoItemCurrent == null) return;
ContentTitle = LangDecorator.GetLang(DemoItemCurrent.Name);
ContentTitle = LangProvider.GetLang(DemoItemCurrent.Name);
});
DataList = dataService.GetDemoDataList();
@ -155,7 +155,7 @@ namespace HandyControlDemo.ViewModel
private void SwitchDemo(DemoItemModel item)
{
DemoItemCurrent = item;
ContentTitle = LangDecorator.GetLang(item.Name);
ContentTitle = LangProvider.GetLang(item.Name);
var obj = AssemblyHelper.ResolveByKey(item.TargetCtlName);
var ctl = obj ?? AssemblyHelper.CreateInternalInstance($"UserControl.{item.TargetCtlName}");
Messenger.Default.Send(ctl is IFull, MessageToken.FullSwitch);

View File

@ -299,7 +299,7 @@ namespace HandyControl.Controls
if (panel == null) return;
var menuItem = new MenuItem();
LangDecorator.SetLang(menuItem, HeaderedItemsControl.HeaderProperty, LangKeys.Clear);
LangProvider.SetLang(menuItem, HeaderedItemsControl.HeaderProperty, LangKeys.Clear);
menuItem.Click += (s, e) =>
{

View File

@ -0,0 +1,21 @@
using System;
using System.Windows.Data;
namespace HandyControl.Data
{
public class EnumDataProvider : ObjectDataProvider
{
private Type _type;
public Type Type
{
get => _type;
set
{
_type = value;
MethodName = "GetValues";
ObjectType = typeof(System.Enum);
MethodParameters.Add(value);
}
}
}
}

View File

@ -49,6 +49,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Text\SimpleText.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Window\GlowWindow.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\DisposableObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\EnumDataProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\DrawerShowMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\HatchStyle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\HitMode.cs" />

View File

@ -6,9 +6,9 @@ using HandyControl.Tools;
namespace HandyControl.Properties.Langs
{
public class LangDecorator : INotifyPropertyChanged
public class LangProvider : INotifyPropertyChanged
{
internal static LangDecorator Instance => ResourceHelper.GetResource<LangDecorator>("Langs");
internal static LangProvider Instance => ResourceHelper.GetResource<LangProvider>("Langs");
private static string CultureInfoStr;

View File

@ -25,9 +25,9 @@ using HandyControl.Tools;
namespace HandyControl.Properties.Langs
{
public class LangDecorator : INotifyPropertyChanged
public class LangProvider : INotifyPropertyChanged
{
internal static LangDecorator Instance => ResourceHelper.GetResource<LangDecorator>("Langs");
internal static LangProvider Instance => ResourceHelper.GetResource<LangProvider>("Langs");
private static string CultureInfoStr;

View File

@ -89,7 +89,6 @@
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="WindowState" Value="Maximized"/>
<Setter Property="Topmost" Value="True"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="controls:WindowAttach.IgnoreAltF4" Value="True"/>

View File

@ -4,7 +4,7 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<langs:LangDecorator x:Key="Langs"/>
<langs:LangProvider x:Key="Langs"/>
</ResourceDictionary>
<ResourceDictionary Source="Basic/Basic.xaml"/>
<ResourceDictionary Source="Styles/Style.xaml"/>

View File

@ -15,7 +15,7 @@ namespace HandyControl.Tools.Extension
public LangExtension()
{
_proxy = new DependencyObject();
Source = LangDecorator.Instance;
Source = LangProvider.Instance;
}
public LangExtension(string key) : this()

View File

@ -42,7 +42,7 @@ namespace HandyControl.Tools
public void SetLang(string lang)
{
LangDecorator.Culture = new CultureInfo(lang);
LangProvider.Culture = new CultureInfo(lang);
Application.Current.Dispatcher.Thread.CurrentUICulture = new CultureInfo(lang);
Lang = XmlLanguage.GetLanguage(lang);
}