任何想法如何我可以做一個點擊事件創建另一個按鈕不同的點擊事件?創建一個提交按鈕,當我按下添加,在一個按鈕下的多個事件
我有一個使用EF的WPF應用程序。所以我被困在我需要按下按鈕「添加」的部分,這將凍結其他按鈕,然後創建另一個按鈕「提交」,其中包含用於向表中添加數據的代碼。我嘗試了一些來自msdn的建議,但它不起作用。下面是代碼(如前面的XAML添加一個名爲B1按鈕):
public partial class RoutedEventAddRemoveHandler {
void MakeButton(object sender, RoutedEventArgs e)
{
Button b2 = new Button();
b2.Content = "New Button";
// Associate event handler to the button. You can remove the event
// handler using "-=" syntax rather than "+=".
b2.Click += new RoutedEventHandler(Onb2Click);
root.Children.Insert(root.Children.Count, b2);
DockPanel.SetDock(b2, Dock.Top);
text1.Text = "Now click the second button...";
b1.IsEnabled = false;
}
void Onb2Click(object sender, RoutedEventArgs e)
{
text1.Text = "New Button (b2) Was Clicked!!";
}
我甚至嘗試了最明顯的解決方案,以簡單直接點擊事件創建點擊事件的另一個按鈕。
我不會動態創建的按鈕,但立即操縱其知名度和或事實啓用yes或no來代替經歷了所有這些麻煩。 –
爲什麼要創建一個新按鈕,當您的xaml中的提交按鈕帶有visible = false並且只是在需要時將其可見性更改爲true時? –
什麼是「根」變量? – Nazmul