0

Good afternoon! I have the following view code (part):

<dxg:TreeListControl x:Name="TlcPropertyGroups" ItemsSource="{Binding CatalogPropertyGroups}"  >
        <dxg:TreeListControl.Columns>
            <dxg:TreeListColumn FieldName="Name"  />
        </dxg:TreeListControl.Columns>
        <dxg:TreeListControl.View>
            <dxg:TreeListView x:Name="TlvPropertyGroups" ShowCheckboxes="True" AllowRecursiveNodeChecking="True"  ShowColumnHeaders="True" TreeDerivationMode="ChildNodesSelector" ChildNodesPath="CatalogPropertyGroupDetails" ShowIndicator="False">
                <dxg:TreeListView.HeaderTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <dxe:TextEdit EditMode="InplaceInactive" Text="Группы свойств"/>
                            <dxe:HyperlinkEdit Grid.Column="1" Text="Настроить" HorizontalAlignment="Right" Command="{Binding SettingCatalogPropertyGroupsCommand}"  DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dx:DXWindow}}}"/>
                        </Grid>
                    </DataTemplate>
                </dxg:TreeListView.HeaderTemplate>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Loaded">
                        <i:InvokeCommandAction Command="{Binding CmdTreeListViewLoaded}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </dxg:TreeListView>
        </dxg:TreeListControl.View>
    </dxg:TreeListControl>

There is the following command:

 private RelayCommand cmdTreeListViewLoaded;

    public RelayCommand CmdTreeListViewLoaded
    {
        get { return cmdTreeListViewLoaded ?? (cmdTreeListViewLoaded = new RelayCommand(obj =>
        {

            //some code


        })); }
    }

Question: how do I pass a delegate as a parameter to the command (to hide some presentation-level logic)? P.S.: as an example, a delegate might display a simple MessageBox.

Anton
  • 163
  • 2
  • 14
  • 1
    See CommandParameter and https://stackoverflow.com/questions/6288641/how-to-use-a-delegate-type-property-in-xaml – GazTheDestroyer May 06 '20 at 08:51
  • Something this article is somehow not informative! – Anton May 06 '20 at 09:42
  • For example, I have a delegate described in the view: public Action ActionMethod = str => { MessageBox.Show(str); }; How can I specify it in the command parameters? – Anton May 06 '20 at 09:47

2 Answers2

0

Try this

<i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">

                     <i:InvokeCommandAction Command="{Binding CmdTreeListViewLoaded}"
                                           CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TreeListView}}" />
                </i:EventTrigger>
    </i:Interaction.Triggers>
Jophy job
  • 1,924
  • 2
  • 20
  • 38
0

Here is the solution:

Part of view code:

 public static Action<string> ActionMethod { get; set; } = str =>
 {
        MessageBox.Show(str);
 };

Part of XAML code:

 <i:Interaction.Triggers>
         <i:EventTrigger EventName="Loaded">
             <i:InvokeCommandAction Command="{Binding CmdTreeListViewLoaded}" CommandParameter="{x:Static tabPanels:PropertyGroupsPanel.ActionMethod}" />
         </i:EventTrigger>
  </i:Interaction.Triggers>

Part of ViewModel code:

 private RelayCommand<Action<string>> cmdTreeListViewLoaded;

    public RelayCommand<Action<string>> CmdTreeListViewLoaded
    {
        get
        {
            return cmdTreeListViewLoaded ?? (cmdTreeListViewLoaded =
                       new RelayCommand<Action<string>>(obj =>
                       {
                           obj.Invoke("Тест!!!");
                       }));
        }
    }
Anton
  • 163
  • 2
  • 14