4.0 WPF 中的子属性数据绑定错误 40

Databinding Error 40 with Sub-Properties in 4.0 WPF

我很难解决我收到的有关我绑定对象的子属性的错误。

输出日志:

System.Windows.Data Error: 40 : 
BindingExpression path error: 
'ModuleTitle' property not found on 'object' ''MainViewModel' (HashCode=20054924)'.
BindingExpression:Path=ModuleTitle; 
DataItem='MainViewModel' (HashCode=20054924); 
target element is 'Module' (Name=''); 
target property is 'Content' (type 'Object')

System.Windows.Data Error: 40 : 
BindingExpression path error: 
'HexColorValue' property not found on 'object' ''MainViewModel' (HashCode=20054924)'. 
BindingExpression:Path=HexColorValue; 
DataItem='MainViewModel' (HashCode=20054924); 
target element is 'Module' (Name=''); 
target property is 'Background' (type 'Brush')

System.Windows.Data Error: 40 : 
BindingExpression path error: 
'ImageSource' property not found on 'object' ''MainViewModel' (HashCode=20054924)'. 
BindingExpression:Path=ImageSource; 
DataItem='MainViewModel' (HashCode=20054924); 
target element is 'Module' (Name=''); 
target property is 'TileGlyph' (type 'ImageSource')

我的看法:

<UserControl definition ...>

<UserControl.DataContext>
    <ViewModels:MainViewModel/>
</UserControl.DataContext>

...


        <dxnav:TileBar x:Name="MainNavigation_TileBar" ScrollViewer.HorizontalScrollBarVisibility="Auto" ItemSpacing="3" ItemsSource="{Binding NavModules}">
            <dxnav:TileBar.ItemContainerStyle>
                <Style TargetType="dxnav:TileBarItem">
                    <Setter Property="Content" Value="{Binding ModuleTitle}"/>
                    <Setter Property="Width" Value="166"/>
                    <Setter Property="Background" Value="{Binding HexColorValue}"/>
                    <Setter Property="TileGlyph" Value="{Binding ImageSource}"/>
                </Style>
            </dxnav:TileBar.ItemContainerStyle>

...

查看模型:

public partial class MainViewModel
{
    public ObservableCollection<Module> NavModules { get { return Module.AvailableNavModules; } }

    public MainViewModel() 
    { 

    }
}

模块Class(属性在构造函数中私下设置):

public class Module : TileBarItem
{
    public string ModuleTitle { get; private set; }

    public string ImageSource { get; private set; }

    public string HexColorValue { get; private set; }

    public string ModuleGroup { get; private set; }

    public string ModuleView { get; private set; }

    public static readonly ObservableCollection<Module> AvailableNavModules = new ObservableCollection<Module>()
    {
        new Module("Search", "/Resources/Icons/Modules/Search.png", ModuleColor.AQUA, _RECORD_GROUP, "SearchPageView"),
        new Module("Record Keeping", "/Resources/Icons/Modules/RecordKeeping.png", ModuleColor.BLACK, _RECORD_GROUP, "RecordKeepingView"),
        new Module("Scheduling", "/Resources/Icons/Modules/Scheduling.png", ModuleColor.ORANGE, _SCHEDULING_GROUP, "SchedulingView"),
        new Module("Management", "/Resources/Icons/Modules/Management.png", ModuleColor.BLUE, _MANAGEMENT_GROUP, "ManagementView")
    };

所有属性都是使用简单的 { get; set; } 实现设置的,就像我在项目的其他地方所做的那样。它只是不适用于此特定用途。当我加载程序时,它正确地加载了对象 NavModules,但是 none 的子属性已设置为显示。

之前忘记在ObservableCollection<Module> NavModules中添加{ get; set; },现在找不到子属性了

建议?

问题是我 ModuleTileBarItem 派生,所以路径没有按预期工作。

新class声明:

public class Module
{
    public string ModuleTitle { get; private set; }
    public string ImageSource { get; private set; }

    ....
}