他のアプリケーションで参照できるプラグインWPFアプリケーションを作成しようとしています。後者は、以前のスタイルを変更できます。異なるアセンブリのWPFオーバーライドスタイル
私の例はXceedのBusyIndicatorに基づいています。私は、私のプラグインのWPFアプリケーションでBusyIndicatorのスタイルを持っていて、そのBusyIndicatorのスタイルを他のアプリケーションで変更したいと思っています。
例:
WPFプラグインアプリケーション:それをOverrideBusyIndicator呼ぶことにしましょう。
<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>
:ソリューションはBusyIndicatorを含むメインウィンドウが存在し、BusyIndicatorスタイルはBusyContextResourceDictionary.xamlの内容はこうです
BusyContextResourceDictionary.xamlにある場合、以下の画像のように見えます
上記のアセンブリを参照する別のソリューションを作成しました。 OverrideBusyIndicator2と呼ぶことにしましょう。これにはメインウィンドウがなく、そのApp.xamlはもう一方のOverrideBusyIndicator.MainWindowを呼び出します。私はBusyContextResourceDictionary2.xamlを追加しました。私はBusyIndicatorのスタイルをオーバーライドするためにを期待していますが、そうではありません。どのような方法で私はこの動作を達成することができますか?ただ、「電子メールをダウンロードしない」ために、「電子メールのダウンロード」からのTextBlockテキストを変更しますBusyContextResourceDictionary2.xamlサンプルの目的で
<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>
。
<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"/>**
私の質問が更新されました。私はデフォルトスタイルのキープロパティについても調べましたが、OverrideBusyIndicator.sln(上記の最初のアプリ)でスタイルを適用できる理由はコントロールを作成したxceedによって既に設定されていると思います。 –
同じターゲットタイプの2つのスタイルがあります。いずれかのキーを指定し、XAMLのこのキーを参照するか、BasedOn属性を使用する必要があります。 –
それを指定していただきありがとうございます。 BasedOnを試しましたが、なぜこれがまだ動作していないのか狂っています(編集を参照)。 –