我想从WPF自定义控件库 实际上从其他文件加载WPF样式,但我无法加载在这里是我的解决方案。从资源文件加载WPF样式
该溶液包含两个项目
WpfTestControls类型WPF定制控件库
WpfTestApp类型的WPF应用程序图书馆,其具有参考WpfTestControls
MainWindow.xaml来自WPF应用程序库
<Window.Resources>
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
</Window.Resources>
<Grid>
<TextBox Height="50px" Width="100px" Style="{DynamicResource TempStyle}"/>
</Grid>
Generic.xaml从WPF自定义控件库
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfTestControls;component/TextBoxStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
TextBoxStyle.xaml从WPF自定义控件库
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
我的AssemblyInfo.cs文件包含以下
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries))]
但我仍无法加载样式。 如果我使用的是不使用Generic.xaml一切做工精细,例如下面的代码按预期工作
<Window x:Class="WpfTestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
</Window.Resources>
<Grid>
<TextBox Height="50px" Width="100px" Style="{StaticResource TempStyle}"/>
</Grid>
我到底做错了什么? 在此先感谢
嗨也许我写错了,但解决方案只包含两个项目类型WPF自定义控件库WpfTestControls和类型Wpf应用程序的WpfTestApp具有引用两个WpfTestControls。 – Robob
正确,所以看到我上面的编辑... –
你是对的,但据我了解,它应该与以前的解决方案。这是我现在要采用的解决方法 – Robob