要根据下拉框条件来显示datagrid的内容,为了不要反复查询,所以用隐藏的方法
前端代码:
<DataGrid Grid.Row="1" x:Name="dataGridTable" ItemsSource="{Binding dt}" >
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="姓名" Binding="{Binding UserName}" CanUserSort="False"></DataGridTextColumn>
<DataGridTextColumn Width="*" Header="账号" Binding="{Binding Account}" CanUserSort="False"></DataGridTextColumn>
<DataGridTextColumn Width="*" Header="状态" Binding="{Binding Status}" CanUserSort="False"></DataGridTextColumn>
</DataGrid.Columns>
<DataGrid.RowStyle >
<Style TargetType="DataGridRow">
<Setter Property="Visibility" Value="{Binding IsShow}" />
</Style>
</DataGrid.RowStyle>
</DataGrid>
后端代码:
dt.IsShow = Visibility.Collapsed;
其中isshow 是visibility属性