我必须承认我无法理解 wpf 的工作方式。我有一个用户控件BottomControl嵌套在我的Mainwindow中。如果单击底部控件中的按钮,我希望主窗口中发生某些更改(例如更改文本框的内容)。
很容易做的事情显然是在 Click_Event 中调用一个公共过程,但这不是很优雅。我已经使用了RoutedCommands。
public static readonly RoutedCommand BottomGridReSize = new RoutedCommand();
在 Usercontrol 的 XAML 中
<Button Style="{StaticResource TransparentButton}" Command="{x:Static local:Commands.BottomGridReSize}" >
在 MainWindow 的代码中
void BottomGridReSize_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
void BottomGridReSize_Executed(object sender, ExecutedRoutedEventArgs e)
{
\\Do some stuff
}
显然 Mainwindow 不能使用这些事件,因为 ist 无法识别它们。我错过了什么?
任何帮助将不胜感激
乔恩