更改自定义按钮的颜色 [英] Change the color of a custom button
本文介绍了更改自定义按钮的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为学校的项目编程游戏,但在处理按钮单击时遇到麻烦.
单击按钮时,我要更改按钮的(背景)颜色.但是我无法通过我的C#代码进行更改.
我已经为按钮使用了模板,但是无法从xaml或C#中更改颜色.
你能帮我吗?
尼科
Hi,
I am programming a game for my project at school and I am having trouble with handling the buttons click.
When the buttons are clicked I want to change the (background)color of the button. But I unable to change it from my C#-code.
I have used a template for my buttons but I can''t change the color from xaml or C#
Can you help me please?
Nico
<Style TargetType="s:SurfaceButton" x:Key="dorpje">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="s:SurfaceButton">
<Grid>
<Ellipse x:Name="Ell" Width="15" Height="15" Stroke="Black" Fill="WhiteSmoke">
<Ellipse.BitmapEffect>
<DropShadowBitmapEffect Color="Black" ShadowDepth="6" Opacity="0.7"/>
</Ellipse.BitmapEffect>
</Ellipse>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
推荐答案
您是说要在按下鼠标左键时更改颜色,还是在单击鼠标后永久更改颜色?
对于第一种选择,您需要添加一个触发器(在XAML中),该触发器在按下按钮时会更改颜色.在第二个步骤中,可以将按钮的Background
属性绑定到单击按钮时设置的形式的属性.为了使绑定生效,您可能必须从INotifyPropertyChanged
派生表单.
Do you mean change color while the left mouse button is down, or change color permenantly after it''s clicked?
For the first choice, you need to add a trigger (in your XAML) that changes the color when the button is pressed. In the second, you could bind the button''sBackground
property to a property in the form that''s set when the button is clicked. You probably have to derive your form fromINotifyPropertyChanged
in order to get that binding to work.
这篇关于更改自定义按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文