昔、私はthis MSDN walkthroughを見ました。それはカラーエディタを実装し、ツールチップは "赤"または "青"のような色の名前を使用します。これらの2つのバインディングの違いは何ですか?
今日、私は同様のListBoxを実装しています。色と色の名前が表示されたボックスが表示されます。私のアプリケーションを除いて、#FFFF0000と#FF0000FFのような16進数の色名がすべて表示されます。どうして?ここで
は両方のプロジェクトで使用されるColorsList
クラスです:
public ColorsList()
{
Type type = typeof(Colors);
foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Static))
{
if (propertyInfo.PropertyType == typeof(Color))
{
Add((Color)propertyInfo.GetValue(null, null));
}
}
}
このXAMLスニペットツールチップは、(あなたがチュートリアルで、コードの残りの部分を見ることができます)MSDNプロジェクトで色の名前を使用します:
ここで<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Tag="{Binding}" Command="{x:Static PropertyEditing:PropertyValueEditorCommands.ShowInlineEditor}">
<Button.Template>
<ControlTemplate>
<Border Width="30" Height="30" BorderBrush="Black" BorderThickness="1" CornerRadius="5">
<Rectangle Width="22" Height="22" ToolTip="{Binding}">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding}"/>
</Rectangle.Fill>
</Rectangle>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
は、16進コードを生成し、私のXAMLです:
<ListBox x:Name="lstColors" Grid.Row="1" ItemsSource="{StaticResource colors}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Stroke="Black"
StrokeThickness="3"
Width="24"
Height="24"
RadiusX="5"
RadiusY="5">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding}" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
それは私には同じように見えます。違いは何ですか?