我无法在Xbox UWP应用弹出窗口中获得选择框 [英] I cannot get the selection box in my Xbox UWP app popup

查看:103
本文介绍了我无法在Xbox UWP应用弹出窗口中获得选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个弹出窗口,上面有一些按钮,我无法选择它们,并且XBox默认选择框也不会出现在按钮周围.

I have created a popup and have some buttons over it and I am not able to select those and nor does the XBox default selection box appears around the button.

<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>

后面的代码:像这样,我无法集中精力查看弹出窗口.我认为它应该自动运行.

Code behind: Its like this and I am not able to get the focus on my popup. I thought it should work automatically.

   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;

        }

    }

}

}

弹出窗口中没有焦点,我无法使用游戏板与之交互.

The focus is not there in the popup and I cannot interact with it using the gamepad.

推荐答案

我将处理弹出窗口的打开事件,

I'd handle the opened event of the popup,

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

弹出式数据模板中的控件将不会位于页面/视图的可视树中,它会具有自己的可视树,为此,您可以使用VisualTreeHelper在弹出式窗口中获取控件以设置焦点./p>

Controls inside your popup datatemplate is not gonna be on the visual tree of your page/view it will kind of have it's own visual tree, for this you can use VisualTreeHelper to get the control inside the popup to set the focus.

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;
}

这篇关于我无法在Xbox UWP应用弹出窗口中获得选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆