自定义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" Value="{Binding Source={StaticResource colorPropertiesOdp}}"></Setter>
<Setter Property="SelectedValuePath" Value="Name"></Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel></WrapPanel>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle" Value="{StaticResource HongColorPickerItemStyle}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid x:Name="MainGrid" SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="32"/>
</Grid.ColumnDefinitions>
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2"
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
<Border x:Name="DropDownBorder" Background="White" BorderBrush="#FFC2C7CB" BorderThickness="1"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=MainGrid}"
MaxWidth="300" Margin="1">
<Border.Effect>
<DropShadowEffect ShadowDepth="6" BlurRadius="12" Opacity="0.2" Direction="270"/>
</Border.Effect>
<Border x:Name="DropDownScrollViewer" Padding="0,2,0,0">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0" ClipToBounds="True">
<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}"
Height="{Binding ActualHeight, ElementName=DropDownBorder}"
Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</Border>
</Border>
</Popup>
<Rectangle Tag="{TemplateBinding SelectedValue}" Fill="{Binding RelativeSource={RelativeSource Self},Path=Tag}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="1" Grid.ColumnSpan="2"></Rectangle>
<ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="Transparent" Grid.ColumnSpan="2"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource HongColorPickerToggleButtonStyle}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"/>
<Trigger Property="HasItems" Value="false">
<Setter Property="Height" TargetName="DropDownBorder" Value="0"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource Disabled}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

wpf自定义colorpicker的更多相关文章

  1. WPF 自定义柱状图 BarChart

    WPF 自定义柱状图 当前的Telerik控件.DevExpress控件在图表控件方面做得不错,但是有时项目中需要特定的样式,不是只通过修改图表的模板和样式就能实现的. 或者说,通过修改当前的第三方控 ...

  2. wpf 自定义圆形按钮

    wpf 自定义圆形按钮 效果图 默认样式 获取焦点样式 点击样式 下面是实现代码: 一个是自定义控件类,一个是控件类皮肤 using System; using System.Collections. ...

  3. WPF自定义窗口基类

    WPF自定义窗口基类时,窗口基类只定义.cs文件,xaml文件不定义.继承自定义窗口的类xaml文件的根节点就不再是<Window>,而是自定义窗口类名(若自定义窗口与继承者不在同一个命名 ...

  4. WPF 自定义 MessageBox (相对完善版)

    WPF 自定义 MessageBox (相对完善版)     基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当 ...

  5. WPF自定义Window样式(2)

    1. 引言 在上一篇中,介绍了如何建立自定义窗体.接下来,我们需要考虑将该自定义窗体基类放到类库中去,只有放到类库中,我们才能在其他地方去方便的引用该基类. 2. 创建类库 接上一篇的项目,先添加一个 ...

  6. WPF自定义Window样式(1)

    1. 引言 WPF是制作界面的一大利器.最近在做一个项目,用的就是WPF.既然使用了WPF了,那么理所当然的,需要自定义窗体样式.所使用的代码是在网上查到的,遗憾的是,整理完毕后,再找那篇帖子却怎么也 ...

  7. WPF自学入门(九)WPF自定义窗口基类

    今天简单记录一个知识点:WPF自定义窗口基类,常用winform的人知道,winform的窗体继承是很好用的,写一个基础窗体,直接在后台代码改写继承窗体名.但如果是WPF要继承窗体,我个人感觉没有理解 ...

  8. WPF自定义TabControl样式

    WPF自定义TabControl,TabControl美化 XAML代码: <TabControl x:Class="SunCreate.Common.Controls.TabCont ...

  9. WPF 自定义ComboBox样式,自定义多选控件

    原文:WPF 自定义ComboBox样式,自定义多选控件 一.ComboBox基本样式 ComboBox有两种状态,可编辑和不可编辑状态.通过设置IsEditable属性可以切换控件状态. 先看基本样 ...

随机推荐

  1. PHP操作MongoDB(增删改查)

    MongoDB的PHP驱动提供了一些核心类来操作MongoDB,总的来说MongoDB命令行中有的功能,它都可以实现,而且参数的格式基本相似.PHP7以前的版本和PHP7之后的版本对MongoDB的操 ...

  2. 通过Java实现斗地主

    功能:洗牌,发牌,对玩家手中的牌排序,看牌 package demo06; import java.util.ArrayList; import java.util.Collections; impo ...

  3. vSphere虚拟化ESXI6.0+vclient安装部署

      知识部分:一.什么是vSphere?vSphere是VNware公司在2001年基于云计算推出的一套企业级虚拟化解决方案.核心组件为ESXi.如今,经历了5个版本的改进,已经实现了虚拟化基础架构. ...

  4. POI 2014 HOTELS (树形DP)

    题目链接 HOTELS 依次枚举每个点,以该点为中心扩展. 每次枚举的时候,从该点的儿子依次出发,搜完一个儿子所有的点之后进行答案统计. 这里用了一个小trick. #include <bits ...

  5. Network | Cookie and Session

    Cookies are arbitrary pieces of data chosen by the web server and sent to the browser. The browser r ...

  6. Aizu 2300 Calender Colors dfs

    原题链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2300 题意: 给你一个图,让你生成一个完全子图.使得这个子图中每个点的最 ...

  7. Codeforces 734C [水][暴力][贪心]

    题意: 要生产n个物品,每个花费时间为x. 有两种魔法,每种最多使用1个. 其中第一种魔法可以使每个物品生产的花费时间变为ai,相应的花费是bi;第二种魔法可以减少ci个物品,相应的花费是di,并且保 ...

  8. Sort Detail Data Block Example - Oracle Forms

    Example is given below to sort detail data block data (toggle asc or desc) with push buttons used as ...

  9. WinRAR4.20注册文件key文件注册码

    1.首先安装rar4.2官方版 2.在WinRAR已安装文件夹内新建文本文档,打开文档,把下面代码复制进去 RAR registration datawncnUnlimited Company Lic ...

  10. python局部变量与全局变量

    name = "head first python"def what_happens_here():    print(name)  1    name = "pytho ...