简体   繁体   English

Windows Phone c#,处于按下状态时如何更改按钮图像?

[英]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.

相关问题 在Windows Phone 8中按下时更改按钮的图像 - Change the image of buttons when pressed in Windows Phone 8 C#在Windows Phone应用程序中按按钮更改图像 - C# change image on button press in a windows phone app 如何在C#Windows Phone中检查和更改名称按钮 - How to check and change name button in C# Windows Phone 按下后退按钮时如何转到Windows Phone 8中的上一页 - How to go to previous page in windows phone 8 when back button is pressed 如何在 c# windows 表单中使用定时器仅在按下按钮时才上下移动电梯? - How to use timer in c# windows form to move elevator up and down only when button is pressed? C# [Windows 窗体] 第二次按下按钮时如何更新 Datagridview 列 - C# [Windows Forms] How to update Datagridview column, when button is pressed a second time 单击后Windows Phone C#更改内容按钮 - WIndows Phone C# change content button AFTER CLICK 当按下表单“b”中的按钮时,如何更改表单“a”中的 label 文本 .net C# - How can I change the label text in form "a" when a button is pressed in form "b" .net C# 在 C# 中按下按钮时如何更改按钮的位置? - How could I change the location of a button whenever it is pressed in C#? C#中如何检测并记录按钮按下的时间? - How to detect and record the time when the button is pressed in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM