Mahapps弹出按钮未与and caliburn.micro一起出现 [英] Mahapps flyout not appearing with and caliburn.micro

查看:120
本文介绍了Mahapps弹出按钮未与and caliburn.micro一起出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用mahapps和caliburn.micro在wpf中显示弹出窗口,不幸的是,弹出窗口的视图尚未解析,我得到的只是弹出窗口中显示的视图模型的类型名称。



我需要根据外壳中的ActiveItem显示弹出窗口,例如公司搜索弹出窗口与联系人搜索弹出窗口不同。



任何想法如何实现这项工作。

 公共无效ShowSearchFlyout()
{
varsupportsSearch = 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控件:Flyout}} TargetType = {x:Type控件: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: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控件:Flyout}} TargetType = {x:Type控件: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()的结果。默认值为类的类型名称(视图模型)。尝试覆盖它。



我希望我能很好地解释为什么需要上述绑定,但是我对WPF / Caliburn / MVVM还是陌生的。也许其他人可以详细说明。但是我认为这可以帮助您继续前进。


I'm trying to show a flyout in wpf using mahapps and caliburn.micro, unfortunately the view for the flyout is not being resolved, and all I get is the type name of the view model displayed in the flyout.

I need the to display the flyout based on which is ActiveItem in the shell, for example the company search flyout is different to the contact search flyout.

Any ideas how I can make this work.

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>

解决方案

The following worked for me:

<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>

In order to get the bindings correct you have to add:

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

If you don't you'll get the result of the function ToString() in the FlyOut. The default is the type name of the class (the viewmodel). Try overriding it.

I whish I could give a good explanation as to why the above binding is needed but I'm fairly new to WPF/Caliburn/MVVM. Maybe someone else can elaborate. However I thought this might help you move on.

这篇关于Mahapps弹出按钮未与and caliburn.micro一起出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆