你能帮帮我吗,为什么当我点击图像,然后点击文本框时,GotFocus和LostFocusa事件没有被触发?
我的XAML:
<Window x:Class="imageclick.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<Image Source="Untitled.png" GotFocus="GF" LostFocus="LF" Focusable="True"></Image>
<TextBox ></TextBox>
</StackPanel>
</Grid>
</Window>我不明白为什么GotFocus/LostFocus事件从未被触发
提前感谢
更新:当我设置表索引时,选项卡到达触发的图像事件时,但鼠标单击无法到达。
发布于 2014-07-07 15:19:54
根据MSDN,当该元素获得逻辑焦点时,就会发生UIElement.GotFocus事件。
逻辑焦点与键盘焦点不同,当路由中元素的IsFocused属性值从false更改为true时,就会引发逻辑焦点。
因此,为了通过鼠标单击来实现它,需要处理相应的鼠标按钮事件,或者简单地处理MouseDown并将焦点设置为发件人。
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
if (sender is Image)
{
(sender as Image).Focus();
}
}这将将图像的IsFocused属性设置为true。
https://stackoverflow.com/questions/24611343
复制相似问题