欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

wpf自定义colorpicker

程序员文章站 2022-06-07 14:07:27
...

自定义colorpicker

<ObjectDataProvider MethodName="GetType"   
                ObjectType="{x:Type system:Type}" x:Key="colorsTypeOdp">
            <ObjectDataProvider.MethodParameters>
                <system:String>System.Windows.Media.Colors, PresentationCore,  
            Version=4.0.0.0, Culture=neutral,   
            PublicKeyToken=31bf3856ad364e35</system:String>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider ObjectInstance="{StaticResource colorsTypeOdp}" MethodName="GetProperties" x:Key="colorPropertiesOdp">
        </ObjectDataProvider>
        <Style x:Key="HongColorPickerItemStyle" TargetType="ComboBoxItem">
            <Setter Property="Margin" Value="1"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBoxItem">
                        <Grid>
                            <Border BorderBrush="#FFC2C7CB" BorderThickness="1" Margin="1">
                                <Rectangle Fill="{Binding Name}" Width="20" Height="18"></Rectangle>
                            </Border>
                            <Rectangle x:Name="Temp_MouseOverRect" Visibility="Collapsed" Stroke="LightBlue" StrokeThickness="1"></Rectangle>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Visibility" TargetName="Temp_MouseOverRect" Value="Visible"></Setter>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Visibility" TargetName="Temp_MouseOverRect" Value="Visible"></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="HongColorPickerToggleButtonStyle" TargetType="{x:Type ToggleButton}">
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="IsTabStop" Value="false"/>
            <Setter Property="Focusable" Value="false"/>
            <Setter Property="ClickMode" Value="Press"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
                            <!--<Grid HorizontalAlignment="Right" Width="32">
                                <Path x:Name="Arrow" Data="M 0 0 L 5 5 L 10 0 Z" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center"  VerticalAlignment="Center"/>
                            </Grid>-->
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="BorderBrush" TargetName="Bd" Value="#FF0D47A1"/>
                                <!--<Setter Property="Fill" TargetName="Arrow" Value="#FF0D47A1"/>-->
                            </Trigger>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="BorderBrush" TargetName="Bd" Value="#FF0D47A1"/>
                                <!--<Setter Property="Fill" TargetName="Arrow" Value="#FF0D47A1"/>-->
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="BorderBrush" TargetName="Bd" Value="#FFAAAAAA"/>
                                <!--<Setter Property="Fill" TargetName="Arrow" Value="#FFAAAAAA"/>-->
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="HongColorPickerStyle" TargetType="{x:Type ComboBox}">
            <Setter Property="Foreground" Value="#FF525E66"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="BorderBrush" Value="#FFC7C7C7"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="Padding" Value="10,0,0,0"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="ItemsSource"