我创建了从常见的Expander继承的自定义WPF Expander。我在路径MyAssembly/Theme/generic.xaml
处有一个包含样式的文件。我可以看到样式应用于设计器但未运行程序。
MyExpander.xaml:
<Expander x:Class="Path.To.MyExpander"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
<Expander.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyAssembly;component/Theme/generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Expander.Resources>
...
generic.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
...
我实例化扩展器的代码:
class Viewer
{
private void GenerateExpanders()
{
this.Expanders.Children.Clear();
foreach (...)
{
MyExpander ex = new MyExpander();
ex.HeaderText.Text = "Sample";
ex.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
ex.IsExpanded = true;
this.Expanders.Children.Add(ex);
}
}
}
所有三个文件都在一个程序集中,但类Viewer在另一个程序集中实例化。 我有什么问题吗?
答案 0 :(得分:0)
我有
<Style TargetType="Expander"
但它应该是
<Style TargetType="MyExpander"
我没有意识到它不再是扩展器 - 它是MyExpander(class MyExpander : Expander
)