私はデータビューのプログラミング言語の設計点から、私にはstyle targettypeを元のプロパティに再バインドする必要があるのはなぜですか?
<Window x:Class="WpfTutorialSamples.Styles.StyleDataTriggerSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="StyleDataTriggerSample" Height="200" Width="200">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<CheckBox Name="cbSample" Content="Hello, world?" />
<TextBlock HorizontalAlignment="Center" Margin="0,20,0,0" FontSize="48">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Text" Value="No" />
<Setter Property="Foreground" Value="Red" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cbSample, Path=IsChecked}" Value="True">
<Setter Property="Text" Value="Yes!" />
<Setter Property="Foreground" Value="Green" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
</Window>
をトリガーにするように、それはすでに、<TextBlock>
内にネストされているので、ライン<Style TargetType="TextBlock">
は、完全に不要であり、コードブロックhereを参照していますどんなセッタープロパティでもTextBlock
タイプに適用する必要があります。だから、なぜラインは<Style TargetType="TextBlock">
が必要ですか?
<Style TargetType>
は、TextBlock
以外のタイプのものもありますか?
*どのようなクラスのTextBlockでも* ---何から派生したものを使用できますか? – Graviton
'class CustomizedTextBlock:TextBlock'は、' TargetType = "TextBlock" '(例えば...)で' Style'を使うことができました。 'TextBlock'自体は' FrameworkElement'から派生しています。だから、 'TextBlock Style'に' TargetType = "FrameworkElement" 'を使うことができます。しかし、私は単純な 'TextBlock'の努力を見ることができません... – WPFGermany