1

有没有人有过使用 Caliburn 和 DevExpress NavBarControl 的经验。我正在尝试将 NavBarItems 列表绑定到我的视图模型。这不起作用,我确定这是因为 Caliburn 的绑定。

例如

<dxnb:NavBarControl x:Name="NavigationBar">
    <dxnb:NavBarControl.Groups>
        <dxnb:NavBarGroup x:Name="NavigationBarGroup" Content="{Binding PluginPresenter}" ImageSource="/Images/Icons/Group.png">
        </dxnb:NavBarGroup>
    </dxnb:NavBarControl.Groups>
    <dxnb:NavBarControl.View>
        <dxnb:NavigationPaneView IsExpandButtonVisible="False"/>
    </dxnb:NavBarControl.View>
</dxnb:NavBarControl>

public class ShellViewModel : PropertyChangeBase
{
   public NavBarItemCollection Plugins { get; set; }
   public NavBarGroup NavigationBarGroup { get; set; }
}
4

1 回答 1

0

我刚开始看 Caliburn Micro。但是,我对使用带有 MVVM 模式的 DevExpress 导航栏进行了一些研究。我向开发团队询问了一个例子。他们说他们的控制中有一个错误阻止它工作。他们确实举了一个变通的例子。链接在这里: http: //www.devexpress.com/Support/Center/p/Q347737.aspx

我查看了他们的解决方案,它对我来说太复杂了,无法使用。希望补丁能尽快推出。

基思

更新 我没有意识到链接不起作用。以下是对解决方案的更详细说明:

  1. 为导航栏创建了一个用户控件:

    <UserControl x:Class="NavBarMVVM.View.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/navbar"
    xmlns:ext="clr-namespace:NavBarExtensions;assembly=NavBarExtensions"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
    <Grid>
        <dxn:NavBarControl x:Name="navBar">
            <dxn:NavBarControl.View>
                <dxn:NavigationPaneView/>
            </dxn:NavBarControl.View>
            <i:Interaction.Behaviors>
                <ext:NavBarMVVMAttachedBehavior ItemsSource="{Binding}">
                    <ext:NavBarMVVMAttachedBehavior.GroupStyle>
                        <Style TargetType="ext:NavBarGroupWrapper">
                            <Setter Property="Header" Value="{Binding Caption}"/>
                            <Setter Property="ItemsSource" Value="{Binding ItemsViewModel}"/>
                        </Style>
                    </ext:NavBarMVVMAttachedBehavior.GroupStyle>
                    <ext:NavBarMVVMAttachedBehavior.ItemStyle>
                        <Style TargetType="ext:NavBarItemWrapper">
                            <Setter Property="Content" Value="{Binding Name}"/>
                            <Setter Property="ImageSource" Value="{Binding PhotoImageSource}"/>
                            <Setter Property="Command" Value="{Binding ClickItemCommand}"/>
                        </Style>
                    </ext:NavBarMVVMAttachedBehavior.ItemStyle>
                </ext:NavBarMVVMAttachedBehavior>
            </i:Interaction.Behaviors>
    
        </dxn:NavBarControl>
    </Grid>
    

这两个 Target 类型是两个称为 *wrapper 的类。他们像这样进行绑定:BindingOperations.SetBinding(NavBarGroup, NavBarGroup.ContentProperty, new Binding("Content") { Source = this });

请注意,这引用了一个名为 NavBarGroup 的类。有四个帮助组。NavBarGroup、NavBarItems、NavBarGroups(List of NavBarGroup) 和 NavBarItems(LIst of NavBarItem) 这些类由另外四个将数据作为静态成员保存的等效类填充。对我来说,正是这些最后的课程破坏了交易。它似乎越界过于复杂。希望有帮助。基思

于 2011-10-26T16:39:30.537 回答