我有一个带有发票清单的视图模型,这些发票通过Telerik RadGridView显示。此RadGridView有一个RowDetailsTemplate。当我单击一行并展开以显示行详细信息时,如何传递所选RadGridViewRow的InvoiceViewModel以便我可以从数据库中获取这些详细信息?
不立即加载所有信息并等待加载细节直到选择行之后的目的是减少加载时间。
以下是一些供参考的代码:
<telerik:RadGridView x:Name="InvoicesGridView"
ItemsSource="{Binding InvoicesForView}" DataContext="{Binding }"
RowDetailsVisibilityMode="VisibleWhenSelected"
// other stuff
telerik:GridViewVirtualizingPanel.IsVirtualizing="False" EnableRowVirtualization="False"
CanUserResizeColumns="False">
<i:Interaction.Triggers>
<i:EventTrigger EventName="RowDetailsVisibilityChanged" SourceObject="{Binding RelativeSource={RelativeSource AncestorType={x:Type telerik:GridViewRow}}}">
<i:InvokeCommandAction Command="{Binding DataContext.LoadInvoice, Source={StaticResource ViewContext}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<telerik:RadGridView.Columns>
<-- Column definitions -->
</telerik:RadGridView.Columns>
<telerik:RadGridView.RowDetailsTemplate>
<-- Row details stuff -->
</telerik:RadGridView.RowDetailsTemplate>
</telerik:RadGridView>
我尝试过选择的InvoiceViewModel并且我得到的所有内容都为null,我可以设置CommandParameter以获取我需要的信息吗?
答案 0 :(得分:0)
<telerik:RadGridView x:Name="InvoicesGridView"
ItemsSource="{Binding InvoicesForView}" DataContext="{Binding }"
ShowGroupPanel="False" Style="{StaticResource TransparentScrollBarStyle}"
RowIndicatorVisibility="Collapsed"
TextElement.Foreground="White"
TextElement.FontSize="12"
FontWeight="Normal" RowDetailsVisibilityMode="VisibleWhenSelected"
AutoGenerateColumns="False" SelectionMode="Multiple"
ShowColumnHeaders="True" RowHeight="24"
CanUserSelect="True" GroupRenderMode="Flat"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.CanContentScroll="True" ColumnWidth="*"
VirtualizingStackPanel.VirtualizationMode="Standard"
telerik:GridViewVirtualizingPanel.IsVirtualizing="False" EnableRowVirtualization="False"
CanUserResizeColumns="False">
<telerik:RadGridView.Columns>
<telerik:GridViewToggleRowDetailsColumn />
<-- Other columns -->
</telerik:RadGridView.Columns>
<telerik:RadGridView.RowDetailsTemplate>
<DataTemplate>
<Grid Background="#f8f8f8" TextElement.Foreground="Black" TextElement.FontWeight="Normal" TextElement.FontStyle="Normal" Margin="-1,0" MinHeight="20">
<telerik:RadTabControl >
<telerik:RadTabItem DataContext="{Binding}"/>
<i:Interaction.Behaviors>
<behaviors:RadTabControlTabChangeCommandBehavior>
<behaviors:RadTabControlTabChangeCommandBehavior.TabChangeCommands>
<behaviors:TabChangeCommand TabIndex="0" Command="{Binding Path=DataContext.LoadInvoice, Source={StaticResource ViewContext}}"/>
</behaviors:RadTabControlTabChangeCommandBehavior.TabChangeCommands>
</behaviors:RadTabControlTabChangeCommandBehavior>
</i:Interaction.Behaviors>
</telerik:RadTabControl>
<-- Other stuff -->
</telerik:RadGridView.RowDetailsTemplate>
</telerik:RadGridView>
以上是一个很好的小工作,对我有用