Cell Template Using Hyperlink in MVVM Template

I am trying to insert a hyperlink in DataGridand find a method to implement the behavior RequestNavigateusing the MVVM pattern.

I have tried many solutions so far, but none of them work. could you help me?

This is my xaml code:

<dgWPFCtrl:ExtDataGridTemplateColumn  Header="Link to XXX"  Width="*">
                    <dgWPFCtrl:ExtDataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock >
                                <Hyperlink NavigateUri="{Binding Path=ID_HTTP_LINK}"
                                           >
                                    <TextBlock Text="{Binding Path=ID_HTTP_LINK}"/>
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="RequestNavigate">
                                            <WPFCtrl:EventToCommand 
                                                PassEventArgsToCommand="True"
                                                Command="{Binding Path=OpenLinkCommand}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Hyperlink>
                            </TextBlock>
                        </DataTemplate>
                    </dgWPFCtrl:ExtDataGridTemplateColumn.CellTemplate>
                </dgWPFCtrl:ExtDataGridTemplateColumn>

and after relative development ICommand:

//Command for open link
RelayCommand _openLinkCommand;
public ICommand OpenLinkCommand
{
    get
    {
        if (_openLinkCommand == null)
            _openLinkCommand = new RelayCommand(param => 
            {
                //Command Body ...
            });
        return _openLinkCommand;
    }
}

Where am I mistaken? Suddenly, ICommandnever called!

I tried to use another event (for example MouseEnter), but nothing has changed!

Thanks in advance for your contributions,

Deby

+5
source share
1 answer

DataContext Hyperlink - , DataGridRow, ViewModel. , , ViewModel ( RelativeSource AncestorType, ElementName).

ElementName ( DataGrid 'myDataGrid')

Command="{Binding ElementName=myDataGrid, Path=DataContext.OpenLinkCommand}"

RelativeSource

Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext.OpenLinkCommand}"
+10

All Articles