首先,我试图遵循MVVM设计模式。
我有一个数据网格。单击行时,rowdetails变为可见。在行详细信息中我有另一个datagrid,让我们调用这个子数据网格。在子数据网格中,其中一列是复选框列,用户可以在其中更新列。 rowdetails在App.xaml中有一个datatemplate。
但是我想在子数据网格旁边添加一个按钮,因此如果用户单击该按钮,它将勾选复选框列中的所有框,而不是必须单击每一行。我可以在rowdetail datatemplate中添加一个按钮,但不知道如何进行绑定?我不知道如何实现对MVVM的保留。
主窗口 - 使用datagrid
<DataGrid Grid.Row="1"
ItemsSource="{Binding HldLogEQCurr, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource DataGridTemplate1}"
ColumnHeaderStyle="{StaticResource DG_ColumnHeaderCenter1}"
RowStyle="{StaticResource DG_Row1}"
CellStyle="{StaticResource DG_Cell1}"
RowHeaderStyle="{StaticResource DG_RowHeader1}"
RowDetailsTemplate="{StaticResource DG_RowDetailRGHTSEX}"
AutoGenerateColumns="False"
HorizontalAlignment="Stretch"
Background="Silver"
Margin="50,50,50,50"
CanUserDeleteRows="False"
CanUserAddRows="False"
RowHeaderWidth="30">
<DataGrid.Columns>
<DataGridTextColumn Header="Date Entered" IsReadOnly="True" Binding="{Binding DateEntered, StringFormat={}\{0:dd-MMM-yy\}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="75"/>
<DataGridTextColumn Header="Date Effective" IsReadOnly="True" Binding="{Binding DateEffective, StringFormat={}\{0:dd-MMM-yy\}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="75"/>
<DataGridTextColumn Header="Sedol" IsReadOnly="True" Binding="{Binding Security.Sedol}" MinWidth="75"/>
<DataGridTextColumn Header="Name" IsReadOnly="True" Binding="{Binding Security.Name}" MinWidth="200"/>
<DataGridTextColumn Header="Ratio" IsReadOnly="True" Binding="{Binding RatioNew}" MinWidth="75"/>
</DataGrid.Columns>
</DataGrid>
的App.xaml
<DataTemplate x:Key="DG_RowDetailRGHTSEX">
<Grid x:Name="RowDetailGrid"
Margin="5"
HorizontalAlignment="Left">
<Border HorizontalAlignment="Left"
VerticalAlignment="Top"
Height="250"
CornerRadius="5">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="Transparent"/>
<GradientStop Offset="1" Color="Transparent"/>
</LinearGradientBrush>
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0"
Grid.Column="0"
Margin="5,5,5,5"
HorizontalAlignment="Left"
FontSize="12"
FontWeight="Bold"
Foreground="Black"
Text="Select action to take">
</TextBlock>
<DataGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
ItemsSource="{Binding SelectedItem.Funds, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
RowStyle="{StaticResource DG_Row}"
ColumnHeaderStyle="{StaticResource DG_ColumnHeader}"
RowHeaderStyle="{StaticResource DG_RowHeaderNested}"
CellStyle="{StaticResource DG_Cell}"
Background="Silver"
HorizontalGridLinesBrush="LightGray"
VerticalGridLinesBrush="LightGray"
CanUserAddRows="False"
CanUserDeleteRows="False"
Margin="50,5,5,20"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Fund Code" Binding="{Binding Code}" IsReadOnly="True" MinWidth="75"/>
<DataGridTextColumn Header="Fund Code SS" Binding="{Binding CodeSS}" IsReadOnly="True" MinWidth="75"/>
<DataGridTextColumn Header="Number of Rights" Binding="{Binding NewNominal, StringFormat={}{0:N0}}" IsReadOnly="True"/>
<DataGridCheckBoxColumn Header="Take Cash" Binding="{Binding OptionOne, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False">
</DataGridCheckBoxColumn>
<DataGridCheckBoxColumn Header="Take Stock" Binding="{Binding OptionTwo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False">
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Column="2" Grid.Row="0" Grid.RowSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
</Grid>
</Grid>
</Border>
</Grid>
</DataTemplate>