【发布时间】:2016-01-03 14:27:02
【问题描述】:
我的 MainWindow 上定义了一些 Flyouts。我想从我的 WPF 应用程序的视图中打开它们。
当我尝试绑定到我的命令时,我没有收到任何错误,但 Flyout 不会打开。当我直接在 MainWindow 中调用 Method 时,Flyout 会打开。
MainWindow.xaml.cs 上的方法
public ICommand openFlyoutHomeCommand { get; private set; }
public void openFlyoutHome()
{
FlyoutHomePlayers.IsOpen = true;
}
以及视图中的绑定,它显示在主窗口中:
<Button Grid.Row="0" Grid.Column="1" Margin="10 30 10 10" Content="Open Flyout" Command="{Binding openFlyoutHome}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"></Button>
【问题讨论】:
-
您最好使用 IEventAggregator 向主窗口发送消息以打开弹出窗口。这将在主窗口的视图模型中处理。引用
IHandle<T>在您的视图模型上继承并订阅事件消息 -
如果您使用的是 Caliburn.Micro MainWindow 不应该在您的项目中。你的主视图应该是 ShellView 而你的“viewmodel”应该是 ShellViewModel
标签: wpf binding caliburn.micro mahapps.metro