改变椭圆的颜色 [英] change color of ellipse

查看:142
本文介绍了改变椭圆的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi



i有组合框中所有颜色的列表



hi

i have list of all color in combo box

<combobox height="23" margin="11,66,11,0" name="comboBox1" verticalalignment="Top" displaymemberpath="Title" selectionchanged="comboBox1_SelectionChanged" selectedindex="0"></combobox>







我有1个椭圆






And i have 1 ellipse

 <ellipse verticalalignment="Center" horizontalalignment="Center" width="280" height="280"> Fill="" StrokeThickness="3" Opacity="22" OpacityMask="Blue"/>

</ellipse>





i想要何时更改椭圆的颜色..通过选择颜色来自组合框...



如何绑定此属性...

Plse帮助我......



i want when to change the color of ellipse .. by selecting color from combo box...

How i can bind this property...
Plse Help Me...

推荐答案

您可以设置椭圆的名称并在代码中设置它,或者您可以在组合框中对所选颜色进行绑定。两种方式都需要设置一个名称(x:Name =)到组合框。
You can set a name for the ellipse and set it in code, or you can do a binding to the selected color in the combobox. Both ways you need to set a name (x:Name=) to the combobox.


你需要一个SolidColorBrush [ ^ ]如果要更改椭圆的填充颜色。设置SolidColorBrush对象的必要属性,然后将其指定给椭圆的Fill属性。当然,在组合框中选择值时,需要设置一些条件,以便在SolidColorBrush对象上设置哪种颜色。 这个 [ ^ ]可能有所帮助。
You need a SolidColorBrush[^] if you want to change the fill color of your ellipse. Set the necessary property of your SolidColorBrush object and then assign it to the Fill property of your ellipse. Of course you need to set some condition on which color to set on your SolidColorBrush object when a value is selected on your combobox. This[^] could probably help.


基本思路是:填充你的组合框,包含您需要的所有画笔。对于列表项内容,请使用 System.Windows.Media.Brushes 的成员,请参阅http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox.aspx [ ^ ]。在 ComboBox.SelectionChanged 事件的处理程序中,键入组合框元素的内容为 SolidColorBrush 和将它分配给属性填写 Ellipse



对于组合框项目,您可以根据需要使用复杂内容;只有在某种嵌套级别拥有 SolidColorBrush 类型的对象时,这一点非常重要。通过这种方式,您可以在组合框列表项中显示颜色,例如它的名称。



这是一个非常简单的例子:



Basic idea is: populate your combo box with all brushes you need. For list item content, use members of System.Windows.Media.Brushes, see http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox.aspx[^]. In the handler of the event of ComboBox.SelectionChanged, type-cast the content of the combo box element to SolidColorBrush and assign it to the property Fill of the Ellipse.

For a combo box item, you can use as complex content as you want; it is only important that you have object of the type SolidColorBrush or Brush at some level of nesting. In this way, you can show color and, for example, its name in the combo box list item.

Here is a very simple example:

<ComboBox>
   <ComboBoxItem>
      <TextBlock Background="Red">Red</TextBlock>  
   </ComboBoxItem>
   <ComboBoxItem>
      <TextBlock Background="Yellow">Yellow</TextBlock>
   </ComboBoxItem>
   <ComboBoxItem>
      <TextBlock Background="AliceBlue">Alice Blue</TextBlock>
   </ComboBoxItem>
</ComboBox>





这不是完美的,只是让你知道你能控制什么(用于颜色选择的组合框。



所有技巧都在设计 ComboBoxItem 内容并使用它。所以,请阅读:

http://msdn.microsoft.com/en -us / library / bb613548.aspx [ ^ ]。



另一个不同级别的WPF自定义绘图是样式模板 。阅读 http://msdn.microsoft.com/en-us/library/ms745683.aspx [ ^ ]。





-SA



It's not perfect, just gives you the idea what can you have for a control (combo box) used for color selection.

All trick is in the design of a ComboBoxItem content and using it. So, read this:
http://msdn.microsoft.com/en-us/library/bb613548.aspx[^].

Another different level of WPF "custom drawing" is styling and templating. Read http://msdn.microsoft.com/en-us/library/ms745683.aspx[^].


—SA


这篇关于改变椭圆的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆