C# 将button.xaml公开给wpf控制器中的另一个类

C# 将button.xaml公开给wpf控制器中的另一个类,c#,xaml,wpf-controls,C#,Xaml,Wpf Controls,我在主窗口中有这个按钮。xaml需要从另一个类调用它 我做的和第一个答案一样 给出错误如果你使用控制器/视图模型,你不应该有任何代码在后面,相反,如果你愿意,你应该在一些基类中使用并实现它。我用C代码修复了它 DispatcherPriority.Background, new Action(() => ((MainWindow)System.Windows.Application.Current.MainWindow).answerCall.V

我在主窗口中有这个按钮。xaml需要从另一个类调用它 我做的和第一个答案一样


给出错误

如果你使用控制器/视图模型,你不应该有任何代码在后面,相反,如果你愿意,你应该在一些基类中使用并实现它。

我用C代码修复了它

 DispatcherPriority.Background,
                    new Action(() => ((MainWindow)System.Windows.Application.Current.MainWindow).answerCall.Visibility = Visibility.Visible));

我不使用controller/viewmodel,只是简单的按钮,我想让它在class.csOk中有价值时可见。我告诉过你,因为你在标题中写了WPF controller。
MainWindow.answerCall.Visibility.Visible;
 DispatcherPriority.Background,
                    new Action(() => ((MainWindow)System.Windows.Application.Current.MainWindow).answerCall.Visibility = Visibility.Visible));