我正在尝试制作一个可以在其他应用程序上引用的插件WPF应用程序,后者可以改变前者的样式。
我的例子是基于Xceed的BusyIndicator。我在我的插件WPF应用程序中有一个BusyIndicator的样式,并希望在其他应用程序上更改该BusyIndicator的样式。
示例:
WPF插件应用程序:我们称之为OverrideBusyIndicator。解决方案如下图所示,其中包含BusyIndicator的MainWindow存在且BusyIndicator样式位于BusyContextResourceDictionary.xaml
BusyContextResourceDictionary.xaml的内容是:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type xceed:BusyIndicator}">
<Setter Property="BusyContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Margin="4">
<TextBlock Text="Downloading Email" FontWeight="Bold" HorizontalAlignment="Center"/>
<StackPanel Margin="4">
<TextBlock Text="Downloading message 4/10..."/>
<ProgressBar Value="40" Height="15"/>
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="Pause" HorizontalAlignment="Right" Margin="0 0 2 0"/>
<Button Grid.Column="1" Content="Cancel" HorizontalAlignment="Left" Margin="2 0 0 0"/>
</Grid>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
我创建了另一个将引用上面的程序集的解决方案。我们称之为OverrideBusyIndicator2。这个没有主窗口,它的App.xaml只调用另一个OverrideBusyIndicator.MainWindow。然后我添加了一个BusyContextResourceDictionary2.xaml I EXPECT 来覆盖BusyIndicator的样式,但事实并非如此。我能以任何方式实现这种行为吗?
<Application x:Class="OverrideBusyIndicator2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit"
StartupUri="pack://application:,,,/OverrideBusyIndicator;component/MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="BusyContextResourceDictionary2.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
出于示例目的,BusyContextResourceDictionary2.xaml将只更改文本块文本&#34;正在下载电子邮件&#34;到&#34;不下载电子邮件&#34;。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/OverrideBusyIndicator;component/BusyContextResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--I am using BasedOn to override the BusyContextResourceDictionary.xaml-->
<Style TargetType="{x:Type xceed:BusyIndicator}" BasedOn="{StaticResource {x:Type xceed:BusyIndicator}}">
<Setter Property="BusyContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Margin="4">
<TextBlock Text="NOT Downloading Email" FontWeight="Bold" HorizontalAlignment="Center"/>**