1、原始代码
<Grid > <i:Interaction.Triggers> <i:EventTrigger EventName="PreviewMouseLeftButtonDown"> <i:InvokeCommandAction Command="{Binding DataContext.MouseLeftButtonDownCommand,RelativeSource={RelativeSource AncestorType=local:PermissionManagementView}}" CommandParameter="{Binding }"></i:InvokeCommandAction> </i:EventTrigger> </i:Interaction.Triggers> <Grid.ColumnDefinitions> <!--需要预留一个--> <ColumnDefinition ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c1" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c2" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c3" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c4" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c5" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c6" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c7" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c8" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c9" ></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Id}" VerticalAlignment="Center" ></TextBlock>
</Grid >
在Grid不加背景颜色的时候点击空白处 时不时无法触发隧道事件PreviewMouseLeftButtonDown
bug解决 增加一个透明背景颜色 触发正常!
Background="Transparent"
<Grid Background="Transparent"> <i:Interaction.Triggers> <i:EventTrigger EventName="PreviewMouseLeftButtonDown"> <i:InvokeCommandAction Command="{Binding DataContext.MouseLeftButtonDownCommand,RelativeSource={RelativeSource AncestorType=local:PermissionManagementView}}" CommandParameter="{Binding }"></i:InvokeCommandAction> </i:EventTrigger> </i:Interaction.Triggers> <Grid.ColumnDefinitions> <!--需要预留一个--> <ColumnDefinition ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c1" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c2" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c3" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c4" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c5" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c6" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c7" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c8" ></ColumnDefinition> <ColumnDefinition SharedSizeGroup="c9" ></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Id}" VerticalAlignment="Center" ></TextBlock> </Grid>
.cs代码
private ICommand _MouseLeftButtonDownCommand; public ICommand MouseLeftButtonDownCommand => _MouseLeftButtonDownCommand ?? (_MouseLeftButtonDownCommand = new DelegateCommand<object>(ExecuteMouseLeftButtonDownCommand)); private void ExecuteMouseLeftButtonDownCommand(object obj) { var sysmenu = obj as SysMenu; if (sysmenu != null) { this.SelectSysMenu = sysmenu; } }
标签:触发,诡异,ExecuteMouseLeftButtonDownCommand,MouseLeftButtonDownCommand,private,Previ From: https://www.cnblogs.com/JohnnyLei/p/17813202.html