Mahapps弹出窗口没有出现和caliburn.micro

时间:2014-02-18 21:37:49

标签: wpf caliburn.micro mahapps.metro

我正在尝试使用mahapps和caliburn.micro在wpf中显示一个弹出窗口,遗憾的是,弹出窗口的视图没有得到解决,我得到的只是弹出窗口中显示的视图模型的类型名称。

我需要在shell中显示基于ActiveItem的弹出窗口,例如公司搜索弹出窗口与联系人搜索弹出窗口不同。

任何想法如何使我的工作。

public void ShowSearchFlyout()
{
    var supportsSearch = ActiveItem as ISupportSearch;
    if (supportsSearch != null)
    {
        if (!Flyouts.Contains(supportsSearch.SearchFlyout))
        {
            Flyouts.Add(supportsSearch.SearchFlyout);
        }
        supportsSearch.SearchFlyout.IsOpen = true;
    }
}
<controls:MetroWindow.Flyouts>
    <controls:FlyoutsControl ItemsSource="{Binding Flyouts}">
        <controls:FlyoutsControl.ItemContainerStyle>
            <Style BasedOn="{StaticResource {x:Type controls:Flyout}}" TargetType="{x:Type controls:Flyout}">
                <Setter Property="Header" Value="{Binding Header}"  />
                <Setter Property="IsOpen" Value="{Binding IsOpen}" />
                <Setter Property="Position" Value="{Binding Position}" />
            </Style>
        </controls:FlyoutsControl.ItemContainerStyle>
    </controls:FlyoutsControl>
</controls:MetroWindow.Flyouts>

1 个答案:

答案 0 :(得分:10)

以下对我有用:

<controls:MetroWindow.Flyouts>
  <controls:FlyoutsControl ItemsSource="{Binding Flyouts}">
    <controls:FlyoutsControl.ItemTemplate>
      <DataTemplate>
        <ContentControl cal:View.Model="{Binding}" />
      </DataTemplate>
    </controls:FlyoutsControl.ItemTemplate>
    <controls:FlyoutsControl.ItemContainerStyle>
      <Style BasedOn="{StaticResource {x:Type controls:Flyout}}" TargetType="{x:Type controls:Flyout}">
        <Setter Property="Header" Value="{Binding Header}"  />
        <Setter Property="IsOpen" Value="{Binding IsOpen}" />
        <Setter Property="Position" Value="{Binding Position}" />
      </Style>
    </controls:FlyoutsControl.ItemContainerStyle>
  </controls:FlyoutsControl>
</controls:MetroWindow.Flyouts>

为了使绑定正确,您必须添加:

    <controls:FlyoutsControl.ItemTemplate>
      <DataTemplate>
        <ContentControl cal:View.Model="{Binding}" />
      </DataTemplate>
    </controls:FlyoutsControl.ItemTemplate>

如果您没有在FlyOut中获得ToString()函数的结果。默认值是类的类型名称(viewmodel)。尝试覆盖它。

我知道我可以很好地解释为什么需要上面的绑定,但我对WPF / Caliburn / MVVM来说还是比较新的。也许其他人可以详细说明。但是我认为这可能会帮助你继续前进。