2016-08-06 10 views
0

他のアプリケーションで参照できるプラグインWPFアプリケーションを作成しようとしています。後者は、以前のスタイルを変更できます。異なるアセンブリのWPFオーバーライドスタイル

私の例はXceedのBusyIndi​​catorに基づいています。私は、私のプラグインのWPFアプリケーションでBusyIndi​​catorのスタイルを持っていて、そのBusyIndi​​catorのスタイルを他のアプリケーションで変更したいと思っています。

例:

WPFプラグインアプリケーション:それをOverrideBusyIndi​​cator呼ぶことにしましょう。

<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> 

enter image description here

:ソリューションはBusyIndi​​catorを含むメインウィンドウが存在し、BusyIndi​​catorスタイルはBusyContextResourceDictionary.xamlの内容はこうです

enter image description here

BusyContextResourceDictionary.xamlにある場合、以下の画像のように見えます

上記のアセンブリを参照する別のソリューションを作成しました。 OverrideBusyIndi​​cator2と呼ぶことにしましょう。これにはメインウィンドウがなく、そのApp.xamlはもう一方のOverrideBusyIndi​​cator.MainWindowを呼び出します。私はBusyContextResourceDictionary2.xamlを追加しました。私はBusyIndi​​catorのスタイルをオーバーライドするためにを期待していますが、そうではありません。どのような方法で私はこの動作を達成することができますか?ただ、「電子メールをダウンロードしない」ために、「電子メールのダウンロード」からの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"/>** 

答えて

0

xceed:BusyIndi​​catorコントロールのスタイルを確認すると便利です。あなたのコントロールのためにdefault style key propertyを定義する必要があるかもしれません。

+0

私の質問が更新されました。私はデフォルトスタイルのキープロパティについても調べましたが、OverrideBusyIndi​​cator.sln(上記の最初のアプリ)でスタイルを適用できる理由はコントロールを作成したxceedによって既に設定されていると思います。 –

+0

同じターゲットタイプの2つのスタイルがあります。いずれかのキーを指定し、XAMLのこのキーを参照するか、BasedOn属性を使用する必要があります。 –

+0

それを指定していただきありがとうございます。 BasedOnを試しましたが、なぜこれがまだ動作していないのか狂っています(編集を参照)。 –

関連する問題