奇妙な状況があります: 次のサンプル コードは、ウィンドウのコンテンツを置き換え、セッターの背景色を使用し、スタック パネルに 2 つのラベルを提供します。1 つは背景用、もう 1 つはタイトル用です。
問題は、設計時
<Label Content="{TemplateBinding Background}" />
にバックグラウンド値を完全に表示します
<Label Content="{TemplateBinding Title}" />
が、それはアプリの実行時のみです。ここでの違いは何ですか?
TargetType をいじってみました (MainWindow に設定しても効果はありません)
これは完全なサンプルです:
<Window x:Class="TBinding.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="350" Width="525">
<Window.Style>
<Style TargetType="Window">
<Setter Property="Background" Value="LawnGreen" />
<Setter Property="Title" Value="The title of this window" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Window">
<StackPanel Margin="50" Background="{TemplateBinding Background}">
<Label Content="{TemplateBinding Background}" />
<Label Content="{TemplateBinding Title}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
</Window>