我有一个WPF应用程序。我有两个数据网格,一个包含指标列表和另一个数据网格,我想要显示顶部数据网格的选定指标的更多详细信息。
但是我的细节网格没有显示任何数据,我无法弄清楚原因。我应该指出主数据网格填充正常。我在属性IndicatorSelected的setter中放了一个中断,并且可以看到当选择一个项目时它被调用&看到数据是正确的,但是没有在详细数据网格中显示。
XAML
<DataGrid x:Name="dgModels" Grid.Column="0"
ItemsSource="{Binding Path=IndicatorList}"
SelectedItem="{Binding Path=IndicatorSelected}"
AutoGenerateColumns="false">
<DataGrid.Columns>
<DataGridTextColumn Header="Model" Binding="{Binding Name}" IsReadOnly="True"/>
<DataGridCheckBoxColumn Header="Run" Binding="{Binding Run}" IsReadOnly="false"/>
</DataGrid.Columns>
</DataGrid>
<DataGrid x:Name="dgParameterInfo" Grid.Column="1"
ItemsSource="{Binding Path=IndicatorSelected}"
AutoGenerateColumns="false">
<DataGrid.Columns>
<DataGridTextColumn Header="Parameter Name" Binding="{Binding Path=Name}" IsReadOnly="True"/>
<DataGridTextColumn Header="Default Value" Binding="{Binding Path=DefaultValue}" IsReadOnly="True"/>
<DataGridTextColumn Header="Run Value" Binding="{Binding Path=RunValue}" IsReadOnly="True"/>
<DataGridTextColumn Header="Parameter Type" Binding="{Binding Path=ParaType}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
C#
class ViewModel : INotifyPropertyChanged
{
List<IndicatorWrapper> _indicatorList;
IndicatorWrapper _indicatorWrapper;
public List<IndicatorWrapper> IndicatorList
{
get { return _indicatorList; }
set
{
_indicatorList = value;
OnPropertyChanged("IndicatorList");
}
}
public IndicatorWrapper IndicatorSelected
{
get { return _indicatorWrapper; }
set
{
_indicatorWrapper = value;
OnPropertyChanged("IndicatorWrapper");
}
}
public ViewModel()
{
DatabaseRetrieveSimulator db = new DatabaseRetrieveSimulator();
IndicatorList = db.GetIndicators();
}
}
答案 0 :(得分:1)
在你的IndicatorSelected setter中,你用IndicatorWrapper调用OnPropertyChanged ......它应该是IndicatorSelected:)