我現在有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