我很难排除这个错误,我收到了绑定对象的子属性。
输出日志:
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()
{
}
}
模块类(属性在构造函数中私有设置):
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
,但没有设置任何子属性进行显示。
以前,我忘记将{ get; set; }
添加到ObservableCollection<Module> NavModules
,但现在我无法找到子属性。
建议?
答案 0 :(得分:0)
问题是我Module
派生TileBarItem
所以道路没有按预期运作。
新课程声明:
public class Module
{
public string ModuleTitle { get; private set; }
public string ImageSource { get; private set; }
....
}