wpf样式的问题
WPF样式的加载是需要将样式文件定义为 ResourceDictionary
现在我们在某个样式DLL中定义style样式,如定义一个Button的样式文件 ControlStyle.xmal:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="HSQCThemesButton" TargetType="{x:Type Button}">
        <Setter Property="BorderBrush" Value="Blue" />
        <Setter Property="Padding" Value="15,5,15,10" />
        <Setter Property="Height" Value="100" />
        <Setter Property="Width" Value="100" />
        <Setter Property="Content" Value="按钮样式" />
    </Style>
</ResourceDictionary>
在另一个组件中引用该DLL,如果需要使用该Button Style,可以有如下操作:

1、在A.xmal中添加样式资源
  <DataTemplate.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/HSQC.Common.Themes;component/Generic.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </DataTemplate.Resources>
2、在A.cs中初始化的时候,加载样式资源
Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/HSQC.Common.Themes;component/Generic.xaml", UriKind.Relative)) as ResourceDictionary);
疑问点:
本以为button style的Key是唯一的,引用的时候是全局引用,发现并不是,这个有待思考,按理是可以通过key唯一找到样式的
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号