如何点击最后一个元素?
说明:用户单击按钮并将鼠标点击模式移动到另一个按钮。因此,应该为最后一个按钮执行click,而不是第一个按钮。
在WPF中,我尝试了所有可能的事件(MouseUp
似乎是正确的选择,但这不符合我的预期。)
如何解决此问题?
UPD :xaml中的2个按钮:
<Button Grid.Column="1" Grid.Row="3" Click="ButtonThigh_OnClick" >
<Grid Width="150" Height="75">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Path=TrackingThighCircumference, Mode=OneWay}"/>
<TextBlock MouseRightButtonDown="Thigh_EditStarted" Height="65" Grid.RowSpan="2">
<TextBox Name="sizeThigh" Background="Transparent" Height="40" IsEnabled="False" ContextMenu="{x:Null}" ContextMenuService.IsEnabled="false" DataObject.Pasting="TextBox_Pasting" MaxLength="6" PreviewTextInput="TextBox_PreviewTextInput" LostFocus="TextBox_LostFocus" KeyUp="TextBox_KeyUp" Tag="ThighCircumferenceUI" Text="{Binding Path=ThighCircumferenceUI, Mode=TwoWay}"></TextBox>
<LineBreak/>
<TextBlock Name="ThighLb" Text="{x:Static strings:Resource.Thigh}"/><Span> (</Span><Span><TextBlock Text="{Binding ElementName=MeasurenentText, Path=Text}"/></Span><Span>)</Span>
</TextBlock>
</Grid>
</Button>
<Button Grid.Column="0" Grid.Row="4" Click="ButtonWaist_OnClick" >
<Grid Width="150" Height="75">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Path=TrackingJacketWaistCircumference, Mode=OneWay}"/>
<TextBlock Grid.Row="1" MouseRightButtonDown="Waist_EditStarted">
<TextBox Name="sizeWaist" Background="Transparent" Height="40" IsEnabled="False" ContextMenu="{x:Null}" ContextMenuService.IsEnabled="false" DataObject.Pasting="TextBox_Pasting" MaxLength="6" PreviewTextInput="TextBox_PreviewTextInput" LostFocus="TextBox_LostFocus" KeyUp="TextBox_KeyUp" Tag="JacketWaistCircumferenceUI" Text="{Binding Path=JacketWaistCircumferenceUI, Mode=TwoWay}"></TextBox>
<LineBreak/>
<TextBlock Name="WaistLb" Text="{x:Static strings:Resource.Waist}"/><Span> (</Span><Span><TextBlock Text="{Binding ElementName=MeasurenentText, Path=Text}"/></Span><Span>)</Span>
</TextBlock>
</Grid>
</Button>
按钮点击次数:
private void ButtonThigh_OnClick(object sender, RoutedEventArgs e)
{
_resultViewModel.SelectMeasurement(si => si.ThighCircumference, vm => vm.ThighImg);
}
private void ButtonWaist_OnClick(object sender, RoutedEventArgs e)
{
_resultViewModel.SelectMeasurement(si => si.JacketWaistCircumference, vm => vm.WaistImg);
}
答案 0 :(得分:0)
您可以在按钮上尝试:
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("1");
}
private void button2_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("2");
}
private void Button1_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
button1_Click(sender,e);
}
private void Button2_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
button2_Click(sender,e);
}
private void Button1_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}
private void Button2_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}