【发布时间】:2012-09-07 11:59:43
【问题描述】:
我使用 WPF 和 MVVM 开发了一个应用程序。在其中我有一个带有 DataGrid 的窗口。它的 ViewModel 包含一些窗口属性和一个 DataGrid 属性(ObservableCollection<DataGridItemViewModel>)。
在window xaml中我这样设置设计DataContext:
<Window x:Class="XXX"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance TheTypeOfTheWindowViewModelHere}">
然后我想以这种方式将设计 DataContext 设置到 DataGrid 上:
<DataGrid ItemsSource="{Binding Path=PropertyOfTheDataGrid}" d:DataContext="{d:DesignInstance DataGridItemViewModel}" >
然后我收到一条警告,告诉我在 DataGridItemViewModel 中找不到 PropertyOfTheDataGrid。
我以为我只设置了 ItemsSource 的 DataContext,但我不确定我做错了还是某种问题。
提前致谢。
【问题讨论】:
标签: c# wpf mvvm resharper datacontext