Hello Alex,
would you please disclose your MyDelgateCommand or do you have the complete example somewhere??
Thanks a beginner..
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
The XAML code is as below.
<DataGrid x:Name="LabelPrintOutputDataList" SelectionMode="Single" ItemsSource="{Binding Path=LabelPrintOutDatas}" AutoGenerateColumns="False" IsReadOnly="True" Visibility="{Binding Path=IsGridVisible,Converter={StaticResource boolToVisibility}}" CanUserSortColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeColumns="False" SelectionUnit="FullRow" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding DoubleClickCommand}" CommandParameter="{Binding ElementName=LabelPrintOutputDataList, Path=CurrentItem}"/>
</i:EventTrigger>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectedItemChangedEvent}" CommandParameter="{Binding ElementName=LabelPrintOutputDataList, Path=CurrentItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
....
</DataGrid.Columns>
</DataGrid>
=================================== ViewModel below
public class LabelPrintOutputMainViewModel : BindableBase
{
public LabelPrintOutputMainViewModel(..........){
DoubleClickCommand = new DelegateCommand<LabelPrintOutData>(LabelPrintOutputListDoubleClicked);
}
private void LabelPrintOutputListDoubleClicked(LabelPrintOutData labelprintoutData)
{
if (labelprintoutData == null) return;
if (labelprintoutData.TRACE == null) return;
this.MakeNewPrintWindow();
this.eventAggregator.GetEvent<LabelPrintOutDoubleClickEvent>().Publish(labelprintoutData);
productlabelprintoutView.ShowDialog();
labelprintoutData = null;
}
public DelegateCommand<LabelPrintOutData> DoubleClickCommand { get; private set; }
}
The values of parameter in LabelPrintOutputListDoubleClicked ( ie; labelprintoutData) method is null while we click more than once. productlabelprintoutView.ShowDialog(); will execute only once for each row in the grid. What would be the reason?
Hello Alex,
would you please disclose your MyDelgateCommand or do you have the complete example somewhere??
Thanks a beginner..
Hi,
Welcome to our Microsoft Q&A platform!
We can continue to discuss this Thread.
why-mousedoubleclickeventtrigger-for-datagrid-works-only-once-on-each-row
I think there is something wrong with the parameters of your LabelPrintOutputListDoubleClicked method,you can see my Test method .
public class MyViewMode
{
public ICommand DoubleClickCommand { get; set; }
public MyViewMode()
{
DoubleClickCommand = new MyDelegateCommand();
(DoubleClickCommand as MyDelegateCommand).ExecuteCommand = Test;
(DoubleClickCommand as MyDelegateCommand).CanExecuteCommand = CanTest;
}
private void Test(object para)
{
MessageBox.Show(GetCellValue((DataGridCellInfo)para).ToString());
}
public object GetCellValue(DataGridCellInfo cellInfo)
{
if (cellInfo != null)
{
var column = cellInfo.Column as DataGridBoundColumn;
if (column != null)
{
var element = new FrameworkElement() { DataContext = cellInfo.Item };
BindingOperations.SetBinding(element, FrameworkElement.TagProperty, column.Binding);
var cellValue = element.Tag;
if (cellValue != null)
return (cellValue);
}
}
return (null);
}
private bool CanTest(object para)
{
return true;
}
}
MVVM Code:
<Grid>
<DataGrid Name="LabelPrintOutputDataList">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding DoubleClickCommand}" CommandParameter="{Binding ElementName=LabelPrintOutputDataList, Path=CurrentCell}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
</Grid>
Thanks.