我在我的应用程序中使用嵌套的RadGridView
。我需要在选择父网格/行时展开子网格/项目。截至目前,只有点击展开图标才能实现功能。
但是要让用户查看子项,我需要在选择行时显示它们,这意味着如果用户点击CheckBox
该行应该展开。
<telerik:RadGridView AutoGenerateColumns="False" CanUserInsertRows="False" IsSynchronizedWithCurrentItem="True" GroupRenderMode="Flat"
GridLinesVisibility="Horizontal" telerik:StyleManager.Theme="Windows8" Grid.Row="1" VerticalAlignment="Top" ClipboardPasteMode="None" ShowGroupPanel="False" ItemsSource="{Binding ItemsCollection, Mode=TwoWay, Source={StaticResource ItemsViewModel}}" RowHeight="30" RowIndicatorVisibility="Collapsed" CanUserReorderColumns="False" AlternationCount="2" IsFilteringAllowed="False" Grid.ColumnSpan="2" >
<telerik:RadGridView.ChildTableDefinitions>
<telerik:GridViewTableDefinition />
</telerik:RadGridView.ChildTableDefinitions>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding IsRelease, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="75" EditTriggers="CellClick" >
<telerik:GridViewDataColumn.Header>
<Grid>
<TextBlock Text="Release" Margin="20, 0, 0, 0" Width="55"/>
<CheckBox Width="15" HorizontalAlignment="Left" Name="chkSelectAll"
IsChecked="{Binding ReleaseIsChecked, Mode=TwoWay, Source={StaticResource ItemsViewModel}}" IsThreeState="False" />
</Grid>
</telerik:GridViewDataColumn.Header>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate >
<CheckBox HorizontalAlignment="Left" Name="chkReleaseItem" telerik:StyleManager.Theme="Windows8"
IsChecked="{Binding IsRelease, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding CheckedChangeCommand, Source={StaticResource ItemsViewModel}}" CommandParameter="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="No" DataMemberBinding="{Binding ItNo, Mode=TwoWay}" IsReadOnly="True" Width="Auto"/>
</telerik:RadGridView.Columns>
<telerik:RadGridView.HierarchyChildTemplate >
<DataTemplate>
<telerik:RadGridView GroupRenderMode="Flat" BorderThickness="0,1,0,1" telerik:StyleManager.Theme="Windows8" GridLinesVisibility="Horizontal" CanUserFreezeColumns="False"
AutoGenerateColumns="False" ItemsSource="{Binding NewItemList}" ShowGroupPanel="False" IsReadOnly="True" AlternationCount="2" IsFilteringAllowed="False" >
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding IsSelect, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="75" EditTriggers="CellClick" >
<telerik:GridViewDataColumn.Header>
<Grid>
<TextBlock Text="Select" Margin="20, 0, 0, 0" Width="55"/>
<CheckBox Width="15" HorizontalAlignment="Left" Name="chkSelectAll" Command="{Binding CheckedAllItemChangeCommand, Source={StaticResource ItemsViewModel}}" IsThreeState="False">
<CheckBox.IsChecked>
<Binding RelativeSource="{RelativeSource AncestorType=telerik:GridViewDataControl}" Path="DataContext.SelectAll" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"/>
</CheckBox.IsChecked>
<CheckBox.CommandParameter>
<MultiBinding Converter="{StaticResource MultiCommandConverter}">
<Binding Path="IsChecked" ElementName="chkSelectAll"/>
<Binding RelativeSource="{RelativeSource AncestorType=telerik:GridViewDataControl}" Path="DataContext.PrototypeId"/>
</MultiBinding>
</CheckBox.CommandParameter>
</CheckBox>
</Grid>
</telerik:GridViewDataColumn.Header>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate >
<CheckBox HorizontalAlignment="Left" Name="chkSelect" telerik:StyleManager.Theme="Windows8" IsChecked="{Binding IsSelect, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Command="{Binding CheckedItemChangeCommand, Source={StaticResource ItemsViewModel}}" >
<CheckBox.CommandParameter>
<MultiBinding Converter="{StaticResource MultiCommandConverter}">
<Binding Path="IsChecked" ElementName="chkSelect"/>
<Binding Path="PrototypeItemId"/>
<Binding Path="PrototypeId"/>
</MultiBinding>
</CheckBox.CommandParameter>
</CheckBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Item No" DataMemberBinding="{Binding ItemNumber, Mode=TwoWay}" IsReadOnly="True" />
<telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Desc, Mode=TwoWay}" IsReadOnly="True" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
<telerik:RadGridView.AlternateRowStyle>
<Style TargetType="{x:Type telerik:GridViewRow}">
<Setter Property="Background" Value="#eae8ed"/>
</Style>
</telerik:RadGridView.AlternateRowStyle>
</telerik:RadGridView>
如何使用MVVM
实现此目的?
答案 0 :(得分:0)
我不熟悉WPF,但在WinForms中,您只需设置要扩展的每一行的IsExpanded
属性即可。包含WinForms示例。
http://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/how-to/expanding-all-rows