我现在有3个按钮,每个按钮都执行特定的任务。在桌面上打开网页或应用程序。但是,我想要一系列指令来遵循这些按钮,因此我使用了Textblock。当我点击按钮时,我想让指令反映哪个按钮被按下,并在3之间不断变化。这将如何完成?WPF点击更新TextBlock
protected void passButton_Click(object sender, RoutedEventArgs e)
{
// I want to be able to surround this is a try catch block statement
// because there is a "Run as Admin" A lot of users may say no and it will crash.
Process myProcess = new Process();
String pathWay = "C:\\blah.txt";
try
//Although we have a working enviornment here we still need to be able to run it as an administrator always
//This would eliminate the need of a "Try/Catch" statement.
{
myProcess.StartInfo.FileName = pathWay;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.Verb = "runas";
myProcess.Start();
}
//Fixed the bug where the app would crash when the user would enter "No" instead of "yes" the App would not launch in this case.
catch
{
Console.WriteLine("Enter so value here for logs later down the road if we run into the problem.");
}
// Here is where I want to be able to change the value incase the user
// clicks another button as of right now the text block updates once
// the block is clicked with a simple "Hello World" but if I click of the value remains the same
textBlock.Text = "Hello world";
你可以发布应用程序代码的简化版本,以便其他人可以帮助调试吗? – laylarenee
嘿Laylarenee,我刚刚添加了上面的一些代码。我希望它清除一些事情! – RyanWilliamWest
你可以为这三个按钮中的每一个添加点击处理程序吗?您只需要包含设置文本的位。 – laylarenee