我已经搜索了很多主题,但已经太复杂了,难以理解。我什至没有看到 this.Invoke();方法。
这是我的场景:
我有一个名为 test1.xaml 的用户控件,它有一个名为frame1 的框架控件
基本上test1.xaml.cs包含
public test1()
{
InitializeComponent();
this.frame1.Content = new test();
}
接下来,我有另一个名为 test2.xaml 的用户控件,我希望它有一个名为 button1 的按钮。我想要发生的是,当加载 test2.xaml 并且用户单击按钮时,我想将其导航页面切换到下一页。
public test2()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MainWindow MW = Application.Current.MainWindow as MainWindow;
MW.label1.Content = MW.tabControl.SelectedIndex;
TabItem page = MW.tabControl.SelectedItem as TabItem;
test1 a = new test1();
a.frame1.Navigate(new Uri(@"/UserControls/salesBtn.xaml", UriKind.Relative));
}
这是我的 test2.xaml.cs 中的代码。现在我知道我在按钮单击事件上做错了,因为我只是实例化一个新的用户控件,而不是引用不再运行的实际控件。如何调用或如何使 test1.xaml 的框架导航到所述路径?
最佳答案
block 引用>I only would just like to manipulate the control property from another class
然后将其公开为公共(public)方法。
例如:
public class MyFirstObject { private string MyValue {get;set;} public void UpdateMyValue(string newValue) { MyValue = newValue; } } public class MySecondObject { MyFirstObject myFirstObject; public MySecondObject { myFirstObject = new MyFirstObject; myFirstObject.UpdateMyValue( "someNewValue" ); } }
关于c# - Invoke方法如何实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4080316/