字体选择器和颜色选择器

<Window x:Class="WpfApplication1.FontColorChooser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="字体选择器" Height="300" Width="300">
    <Window.Resources>
        <CollectionViewSource x:Key="sysFonts" Source="{x:Static Fonts.SystemFontFamilies}" />
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ComboBox Name="cbFont" ItemsSource="{Binding Source={StaticResource sysFonts}}" IsSynchronizedWithCurrentItem="True">
            <ComboBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel />
                </ItemsPanelTemplate>
            </ComboBox.ItemsPanel>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}" FontFamily="{Binding}" FontSize="16" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <StackPanel Grid.Row="2" HorizontalAlignment="Center">
            <TextBlock Text="预览" />
            <TextBlock Text="常伟华 Changweihua www.cmono.net" FontSize="20" FontFamily="{Binding Source={StaticResource sysFonts},Path=/}" />
        </StackPanel>
    </Grid>
</Window>

<Window x:Class="WpfApplication1.ColorChooser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="颜色选择器" Height="300" Width="300">
    <Window.Resources>
        <ObjectDataProvider MethodName="GetType" ObjectType="{x:Type sys:Type}" x:Key="odpColor">
            <ObjectDataProvider.MethodParameters>
                <sys:String>
                    System.Windows.Media.Colors, PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
                </sys:String>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider ObjectInstance="{StaticResource odpColor}" MethodName="GetProperties" x:Key="odpColorProperty" />
    </Window.Resources>
    <StackPanel>
        <ComboBox Name="cb1" HorizontalAlignment="Stretch" ItemsSource="{Binding Source={StaticResource odpColorProperty}}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Rectangle Fill="{Binding Name}" Margin="1 3" Height="10" Width="100" />
                        <TextBlock Text="{Binding Name}" Margin="2 0" />
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <Rectangle Fill="{Binding ElementName=cb1,Path=SelectedItem.Name}" Margin="1 3" Height="10" Width="100" />
        <TextBlock Text="{Binding ElementName=cb1,Path=SelectedItem.Name, StringFormat=你选择了{0}}" Margin="2 0" />
    </StackPanel>
</Window>


知识共享许可协议
《字体选择器和颜色选择器》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     157.25ms