简体   繁体   中英

InvokeCommandAction CommmandParameter

I have a view model with a list of Invoices, these invoices are being displayed via a Telerik RadGridView This RadGridView has a RowDetailsTemplate. When I click on a row and expand to show the row details how can I pass the InvoiceViewModel of the selected RadGridViewRow so I can get those details from the database?

The purpose of not loading all of the information at once and waiting to load the details until after the row is selected is to reduce load time.

Here's some code for reference:

            <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>

I've tried passing through a selected InvoiceViewModel and all that I get back is null, What can I set the CommandParameter to too get the information I need?

            <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>

The above is a nice little work around that worked for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM