Feedback

C# - Alle verfügbaren Farben mittels WPF ausgeben

Veröffentlicht von am 4/15/2008
(2 Bewertungen)
namespace WpfApplication
{
public class Tools
{
public PropertyInfo[] GetColors(Type type)
{
return type.GetProperties();
}
}
}

Vergesst nicht das einbinden des Namespaces von System.Reflection.
<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>
Abgelegt unter wpf, color, farben, farbe, xaml.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!