[英]Trying to change a button's border color in Xamarin code behind on a Clicked event
This just doesn't seem to be working, but of course, I feel like it really should be.这似乎不起作用,但当然,我觉得它确实应该如此。 Can't figure out what's wrong here.
无法弄清楚这里出了什么问题。 I have a button with a border that's set to transparent in the xaml.
我有一个在 xaml 中设置为透明边框的按钮。 I want the border color to change to white when the button is pressed.
我希望按下按钮时边框颜色变为白色。 Very simple.
很简单。 But yeah, any help would be appreciated.
但是,是的,任何帮助将不胜感激。 Here's my event:
这是我的活动:
private void FactionChosen(object sender, EventArgs e)
{
if ((sender as Button).BorderColor == Color.Transparent)
{
(sender as Button).BorderColor = Color.White;
}
else if ((sender as Button).BorderColor == Color.White)
{
(sender as Button).BorderColor = Color.Transparent;
}
}
Thanks in advance提前致谢
As mentioned previously in my comment , two possible reasons could be the cause:正如我之前在评论中提到的,可能的原因有两个:
BorderWidth
, by default it has 0 as valueBorderWidth
设置值, 默认情况下它的值为 0 <Button Text="OK" BorderWidth="3" BorderColor="Transparent" Clicked="FactionChosen"/>
Button
is in a white background (the BackgroundColor
of it Parent is white), it is straightforward that the BackgroundColor
of the Parent control and the BorderColor
of your Button must be different.Button
处于白色背景(其 Parent 的BackgroundColor
为白色),很简单,Parent 控件的BackgroundColor
和您的 Button 的BorderColor
必须不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.