1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<Window x:Class="WpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:WpfApplication"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Colors" Height="200" Width="300">
<Window.Resources>
<ObjectDataProvider x:Key="colors" MethodName="GetColors" ObjectType="{x:Type local:Tools}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="Colors"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<DataTemplate x:Key="dTemplate">
<StackPanel Orientation="Horizontal">
<Rectangle Width="16" Height="12" Fill="{Binding Name}" Stroke="#FF000000"/>
<TextBlock Margin="1" Text ="{Binding Name}" Foreground="{Binding Name}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ComboBox ItemsSource="{Binding Mode=OneWay, Source={StaticResource colors}}" ItemTemplate="{DynamicResource dTemplate}" Margin="50,50,50,0" VerticalAlignment="Top" />
</Grid>
</Window>
|