[英]Windows Phone c#, how to change button image when in pressed state?
For a C# Windows Phone app, how does one have a button that has a .png background, and then the background changes upon a press? 对于C#Windows Phone应用程序,如何具有一个具有.png背景的按钮,然后在按下时背景发生变化? To word it a little differently, how can I change the button's background image for the pressed state?
换句话说,我如何更改按钮状态的背景图像?
I have a button that I set the background through blend to be a png image. 我有一个按钮,我通过混合将背景设置为png图像。 When I go to blend, right click the button and click edit a copy for the template, I click on the pressed state and it goes red showing it is recording.
当我进行混合时,右键单击该按钮,然后单击“编辑模板的副本”,然后单击按下的状态,该状态变为红色表示正在记录。 I then go to change the background image but there is a yellow border around it.
然后,我去更改背景图像,但是它周围有一个黄色边框。 I cannot change it.
我无法更改。 If I reset the value so the border goes away I get a warning saying I broke animations.
如果重置该值以使边框消失,则会收到警告,提示我破坏了动画。 If I ignore it and set it anyway, it sets the "pressed" image as the default image and all states have that image now.
如果我忽略它并进行设置,它将“按下”图像设置为默认图像,并且所有状态现在都具有该图像。
I can't figure out how to make this button just be an image and then display a different image when pressed, and back to the original image when unpressed. 我无法弄清楚如何使此按钮成为图像,然后在按下时显示不同的图像,而在未按下时又回到原始图像。
This is how I do it programatically to create a "blink" effect when someone presses one of my four arrow images from my on-screen control pad (I re-load the same image, you could load your other image instead): 当有人从屏幕控制板上按下我的四个箭头图像之一时,这是我通过编程方式创建“闪烁”效果的方式(我重新加载相同的图像,也可以加载其他图像):
private void imLeft_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
_wormDirection = Direction.Left;
((Image)sender).Source = null;
}
private void imLeft_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
System.Threading.Thread.Sleep(25);
((Image)sender).Source = imLeftImageSource;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.