3

我有 Page,当我点击它的空白部分时它会失去焦点。我尝试将边框作为背景,但是当我点击它时它也会失去焦点。为什么会这样?

我真正需要做的是在用户打开 AppBar 或 Settings Charm 时禁用 WebView

一些演示问题的示例代码(观看输出窗口):

XAML:

<Page
    x:Name="Pagey"
    x:Class="FocusTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FocusTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" GotFocus="Focus" LostFocus="LoseFocus">

    <Grid x:Name="RootGrid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" GotFocus="Focus" LostFocus="LoseFocus">
        <StackPanel>
            <Button x:Name="Clicky" Content="Clicky" GotFocus="Focus" LostFocus="LoseFocus" HorizontalAlignment="Center"></Button>
            <Border x:Name="Border" Width="100" Height="100" Background="Red" GotFocus="Focus" LostFocus="LoseFocus"></Border>
            <Button x:Name="Clicky2" Content="Clicky2" GotFocus="Focus" LostFocus="LoseFocus" HorizontalAlignment="Center"></Button>
        </StackPanel>
    </Grid>
</Page>

后面的代码:

using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace FocusTest
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        void Focus(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Focus({0})", (sender as FrameworkElement).Name);
        }

        void LoseFocus(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("LoseFocus({0})", (sender as FrameworkElement).Name);
        }
    }
}
4

1 回答 1

1

看起来你Border在里面RootGrid所以每次点击Border's tap event都会发生并LostFocus触发事件。

更好的是,您可以LostFocus在相同的RootGrid. 然后它可能工作正常。
请尝试一下。谢谢。

于 2013-03-15T09:54:01.137 回答