4

Royale テーマ スタイルに加えて、すべてのボタンに 5 ポイントのマージンが必要です。

Window1.xaml:

<Window x:Class="_styles.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
  <Window.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/PresentationFramework.Royale;component/themes/royale.normalcolor.xaml" />
      </ResourceDictionary.MergedDictionaries>
      <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
        <Setter Property="Margin" Value="5"/>
      </Style>
    </ResourceDictionary>
  </Window.Resources>
  <StackPanel>
    <Button Content="Button A"/>
    <Button Content="Button B"/>
  </StackPanel>
</Window>

コンパイルされますが、次のようになります。

型 'System.StackOverflowException' の未処理の例外が PresentationFramework.dll で発生しました

public Window1() {
    InitializeComponent(); // <-- getting exception here
}

次の理由により、例外の詳細はありません。

{現在のスレッドがスタック オーバーフロー状態にあるため、式を評価できません。}

4

3 に答える 3

5

これは、あなたのスタイルと PresentationFramework.Royale で定義されているスタイルとの間の循環参照のようです。回避策は、リソースをさまざまなレベルに配置することです。

<Window x:Class="_styles.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="Window1" Height="300" Width="300">
<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/PresentationFramework.Royale;component/themes/royale.normalcolor.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
<StackPanel>
    <StackPanel.Resources>
        <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
            <Setter Property="Margin" Value="5"/>
        </Style>
    </StackPanel.Resources>
    <Button Content="Button A"/>
</StackPanel>
</Window>
于 2009-10-09T09:32:21.270 に答える
0

すべてのウィンドウでリソースディクショナリを指定する必要がなく、BasedOnスタイルを動的に解決できる別のソリューションについては、この質問私の回答を参照してください。

于 2010-06-23T07:26:14.053 に答える
0

BasedOn 属性を削除しますが、必要ありません。このように考えると、Royale テーマをマージするとボタン テーマが適用され、余白を変更したいだけです。意味がある?

乾杯!

于 2009-05-29T18:02:20.460 に答える