我无法在我的 Xbox UWP 应用程序弹出窗口中获取选择框

I cannot get the selection box in my Xbox UWP app popup

我创建了一个弹出窗口,上面有一些按钮,但我无法select这些按钮,而且 XBox 默认 selection 框也没有出现在按钮周围。

<Grid>

    <StackPanel HorizontalAlignment="Center" Margin="0,50,0,0">

        <Button Content="Show Popup Flyout" Click="ShowFlyoutPopup" />

    </StackPanel>

    <Popup x:Name="logincontrol1" IsOpen="False" IsLightDismissEnabled="True">

        <Popup.ChildTransitions>

            <TransitionCollection>

                <PaneThemeTransition />

            </TransitionCollection>

        </Popup.ChildTransitions>
        <StackPanel Orientation="Vertical" Background="#313131" Width="1000" Height="500"  x:Name="pop" Margin="0,100,0,0" >

            <StackPanel>
                <GridView ItemsSource="{Binding GamesList}" >
                <GridView.ItemTemplate>
                    <DataTemplate x:Name="testtemp">
                            <Button x:Name="SwapBtn" Command="{Binding TestClick,Mode=OneWay}">
                            <StackPanel Width="202" VerticalAlignment="Top">
                                <Image Source="{Binding ImageUrl}" Height="324"/>
                                <StackPanel Background="Black" Padding="19,9,0,0">
                                    <TextBlock FontWeight="Semibold" TextTrimming="CharacterEllipsis" FontFamily="Segoe Pro" Foreground="White" TextAlignment="Left" FontSize="24" Text="{Binding Title}" TextWrapping="Wrap" Height="65"/>
                                    <TextBlock FontFamily="Segoe Pro" Foreground="White" TextAlignment="Left" FontSize="16" Text="{Binding Price}" Margin="0,48,0,0"/>
                                </StackPanel>
                            </StackPanel>
                        </Button>
                        </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>

            </StackPanel>

        </StackPanel>
    </Popup>

</Grid>

代码隐藏:就像这样,我无法将焦点放在我的弹出窗口上。我认为它应该会自动运行。

   public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }
    private void ShowFlyoutPopup(object sender, RoutedEventArgs e)

    {

        if (!logincontrol1.IsOpen)

        {

            RootPopupBorder.Width = 646;
            logincontrol1.HorizontalOffset = Window.Current.Bounds.Width - 1485;

            logincontrol1.VerticalOffset = Window.Current.Bounds.Height - 840;

            logincontrol1.IsOpen = true;

        }

    }

}

}

焦点不在弹出窗口中,我无法使用游戏手柄与之互动。

您可以强制关注 Popup 的控件之一:

logincontrol1.IsOpen = true;
loginclick.Focus(FocusState.Programmatic);

我会处理弹窗的打开事件,

<Popup x:Name="logincontrol1" IsOpen="False" IsLightDismissEnabled="True" Opened="Logincontrol1_OnOpened">

弹出数据模板中的控件不会出现在 page/view 的可视化树上,它会有自己的可视化树,为此您可以使用 VisualTreeHelper 获取弹出式窗口中的控件以进行设置重点.

private void Logincontrol1_OnOpened(object sender, object e)
{
    Popup popup = sender as Popup;
    if (popup != null)
    {
        Button button = FindElementInVisualTree<Button>(mygrid);
        button?.Focus(FocusState.Programmatic);
    }
}

private T FindElementInVisualTree<T>(DependencyObject parentElement) where T : DependencyObject
{
    var count = VisualTreeHelper.GetChildrenCount(parentElement);
    if (count == 0) return null;

    for (int i = 0; i < count; i++)
    {
        var child = VisualTreeHelper.GetChild(parentElement, i);
        if (child != null && child is T)
            return (T)child;
        else
        {
            var result = FindElementInVisualTree<T>(child);
            if (result != null)
                return result;
        }
    }
    return null;
}