我有 2 个数据网格。应根据基于第一个数据网格的选择的选择标准从数据库中获取数据。它需要填充第二个数据网格。
在wpf中有什么最好的方法吗?
这是我的 xaml 的代码:
<cmcCtl:CmcDataGrid x:Name="QueueSearchCampusGrid"
Canvas.Left="0"
Canvas.Top="0"
Width="572"
Height="114"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AutoGenerateColumns="False"
SelectionChanged="CmcDataGrid_OnSelectionChanged"
SelectedItem="{Binding Path=SelectedValue}"
ItemsSource="{Binding ProspectiveCampusList}">
<cmcCtl:CmcDataGrid.Columns>
<toolkit:DataGridTemplateColumn CanUserReorder="False"
CanUserResize="False"
CanUserSort="False"
ClipboardContentBinding="{x:Null}"
IsReadOnly="False">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
<toolkit:DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type toolkit:DataGridCell}">
<EventSetter Event="UIElement.PreviewMouseLeftButtonUp" Handler="DataGridCell_PreviewMouseLeftButtonUp" />
<EventSetter Event="UIElement.PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown" />
</Style>
</toolkit:DataGridTemplateColumn.CellStyle>
</toolkit:DataGridTemplateColumn>
<toolkit:DataGridTextColumn Binding="{Binding CampusCode}"
ClipboardContentBinding="{x:Null}"
Header="Campus Code" />
<toolkit:DataGridTextColumn Binding="{Binding CampusDescription}"
ClipboardContentBinding="{x:Null}"
Header="Campus" />
</cmcCtl:CmcDataGrid.Columns>
</cmcCtl:CmcDataGrid>
<CheckBox x:Name="CheckBoxCampusHeadSelect"
Canvas.Left="4"
Canvas.Top="4"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content=""
Checked="CheckBoxHeadSelect_Checked"
IsThreeState="False"
Unchecked="CheckBoxHeadSelect_Unchecked" />
</Canvas>
<Canvas Grid.Row="3"
Width="572"
Height="112"
Margin="0,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<cmcCtl:CmcDataGrid x:Name="QueueSearchProgramVersionGrid"
Canvas.Left="0"
Canvas.Top="0"
Width="572"
Height="114"
SelectionMode="Single"
SelectionUnit="FullRow"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ItemsSource="{Binding QueueSearchProgramVersionList}">
<cmcCtl:CmcDataGrid.Columns>
<toolkit:DataGridTemplateColumn CanUserReorder="False"
CanUserResize="False"
CanUserSort="False"
ClipboardContentBinding="{x:Null}"
IsReadOnly="False">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
<toolkit:DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type toolkit:DataGridCell}">
<EventSetter Event="UIElement.PreviewMouseLeftButtonUp" Handler="DataGridCell_PreviewMouseLeftButtonUp" />
<EventSetter Event="UIElement.PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown" />
</Style>
</toolkit:DataGridTemplateColumn.CellStyle>
</toolkit:DataGridTemplateColumn>
<toolkit:DataGridTextColumn Width="85"
Binding="{Binding CampusCode}"
ClipboardContentBinding="{x:Null}"
Header="Campus Code" />
<toolkit:DataGridTextColumn Width="100"
Binding="{Binding CampusDescription}"
ClipboardContentBinding="{x:Null}"
Header="Campus" />
<toolkit:DataGridTextColumn Binding="{Binding ProgramVersionCode}"
ClipboardContentBinding="{x:Null}"
Header="Program Code" />
<toolkit:DataGridTextColumn Binding="{Binding ProgramVersionDescription}"
ClipboardContentBinding="{x:Null}"
Header="Program Version" />
</cmcCtl:CmcDataGrid.Columns>
</cmcCtl:CmcDataGrid>
<CheckBox x:Name="CheckBoxProgramVersionHeadSelect"
Canvas.Left="4"
Canvas.Top="4"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content=""
Checked="CheckBoxHeadSelect_Checked"
IsThreeState="False"
Unchecked="CheckBoxHeadSelect_Unchecked" />
</Canvas>
</Grid>
这是我的模型类的代码:
public ShoppingSheetQueueSearchClient SelectedValue
{
get
{
return _selectedValue;
}
set
{
if (_selectedValue == value) return;
_selectedValue = value;
BindQueueSearchProgramVersionGridControl();
}
}