0

の下<Window.Resources>に、次のスタイルが定義されています。

    <Style TargetType="TextBox">
        <Setter Property="Height" Value="22" />
        <Setter Property="Width" Value="125" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="Background" Value="WhiteSmoke" />
    </Style>

別のスタイルでスタイルを継承する必要があるまでは問題なく動作します

<Style BasedOn="{StaticResource TextBoxStyle}" TargetType="{x:Type PasswordBox}">

つまり、x:Key=TextBoxStyle上記のテキスト ボックス スタイルに を追加する必要があります。
しかし、これを行うと、テキスト ボックスのスタイルが完全に壊れてしまいます。
ボタンのスタイリングにも同じことをしようとしましたが、同じことが起こり、キーを追加するとスタイルが壊れます。

私が考えた唯一の解決策は、スタイルを要素に個別に追加することですが、それは私がやろうとしていることです。

4

2 に答える 2

2

いいえ、それを参照するために追加する必要はありませんx:Key:

<Style BasedOn="{StaticResource {x:Type TextBox}}" TargetType="{x:Type PasswordBox}">
于 2013-05-13T04:24:49.320 に答える
0

より良い理解と保守を提供するために、次のアプローチをお勧めします。IMHO、暗黙性が最小限に抑えられれば、別のプログラマーがコードに慣れる可能性があります。

<Style x:Key="BasicTextBoxStyle" TargetType="{x:Type TextBox}">
    <!--some settings here-->
</Style>

<!--Declare BasicTextBoxStyle as default style for TextBoxes-->
<Style BasedOn="{StaticResource BasicTextBoxStyle}" TargetType="{x:Type TextBox}"/>

<!--Create some special style based on the basic style-->
<Style BasedOn="{StaticResource BasicTextBoxStyle}" TargetType="{x:Type PasswordBox}">
    <!--some more specific settings-->
</Style>

ちょうど私の2セント...

于 2013-05-13T07:38:41.170 に答える