背景piker颜色 [英] Background piker color
问题描述
我正在尝试创建一个可编辑的 Combobox
(我写的是我想要的)使用彩色Piker,这是在 Combobox
的下拉弹出窗口中有一个所有可能颜色的列表,当我选择一个时, Combobox
更改。
这是可能的以及如何?
Best问候
Filipe Marques
Hi,
I am trying to create a editable Combobox
(where I write what I want) with a color piker, this is, in the dropdown popup of the Combobox
there is a list of all possible colors and when I choose one, the background of Combobox
changes.
This is possible and how?
Best regards
Filipe Marques
推荐答案
我想出一个解。我不知道它是不是最好的(我几乎100%不是)但是工作:D
继承人代码。
XAML
Hi,
I figure out a solution. I do not know if it is the best one (I am almost 100% that is not) but ir works :D
Heres the code.
XAML
<usercontrol x:class="WpfCoWorker.CoWorkerSeparatorControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:osc="clr-namespace:WpfCoWorker"
Name="coworkercontrol"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<border name="mainborder" removed="{Binding ElementName=colorpicker, Path=SelectedBrush}">
<grid>
<grid.columndefinitions>
<columndefinition width="*" />
<columndefinition width="22" />
</grid.columndefinitions>
<textbox name="texbox">
Margin="0"
Padding="0"
Grid.Column="0"
Height="Auto"
Background="{Binding ElementName=colorpicker, Path=SelectedBrush}"
Text="{Binding Text, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
<osc:comboboxcolorpicker x:name="colorpicker" xmlns:osc="#unknown">
SelectedColor="White"
ColorChanged="colorpicker_ColorChanged"
HorizontalAlignment="Left"
Grid.Column="1"/>
</grid>
</border>
</usercontrol>
和de C#代码
And de C# code
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace WpfCoWorker
{
public partial class CoWorkerSeparatorControl : UserControl
{
public String IText
{
get { return this.texbox.Text; }
}
public Color IColor
{
get { return this.colorpicker.SelectedColor; }
}
public String Text
{
get { return (String)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(String),
typeof(CoWorkerSeparatorControl), new PropertyMetadata(""));
public Color BckColor
{
get { return (Color)GetValue(BckColorProperty); }
set { SetValue(BckColorProperty, value); }
}
public static readonly DependencyProperty BckColorProperty =
DependencyProperty.Register("BckColor", typeof(Color),
typeof(CoWorkerSeparatorControl), new PropertyMetadata(Colors.Transparent));
public CoWorkerSeparatorControl()
{
InitializeComponent();
}
}
}
osc:ComboBoxColorPicker
是这个控件:http://www.codeproject.com/Articles/34376/Small-ColorPicker-for-WPF
我希望这有助于有人。
最好的问候
Filipe Marques
The osc:ComboBoxColorPicker
is this control: http://www.codeproject.com/Articles/34376/Small-ColorPicker-for-WPF
I hope this helps someone.
Best regards
Filipe Marques
这篇关于背景piker颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!