WinRT中组合框的奇怪行为 [英] Strange behaviour of combobox in WinRT

查看:78
本文介绍了WinRT中组合框的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WinRT中的组合框具有CarouselPanel类型的默认ItemsPanel。当滚动组合框项目时,这使Windows 8.1应用程序无限循环。
如果您不希望这种行为,那么会有很多博客文章解释如何修复。

Comboboxes in WinRT have a default ItemsPanel of type CarouselPanel. This gives Windows 8.1 apps an "infinite loop" when scrolling combobox items. If you don't want this behaviour, there are a lot of blog posts explaining how to "fix it".

例如:取消WinRT ComboBox无限滚动效果
或:> http://netitude.bc3tech.net/2013/04/12/ Windows-8s-combobox-and-the-carouselpanel /

此解决方案的问题是,您在组合框中的第一个项目上出现了奇怪的行为。
如何复制:

The problem with this solution is that you get a weird behaviour on the first item in the combobox. How to reproduce:


  • 创建一个新的空白Windows 8.1应用程序

  • 在mainpage.xaml中:

  • Create a new blank Windows 8.1 app
  • In mainpage.xaml put:

<TimePicker Time="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>


  • 创建一个style.xaml资源字典,如下所示:

  • Create a style.xaml resource dictionary like this:

    <Style TargetType="ComboBox">
        <Style.Setters>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>
    


  • 现在启动应用程序,从列表中选择一项(例如'05'minutes ),然后在同一下拉列表中选择第一项(例如'00'分钟)。下拉控件中的文本现在将消失。

  • Now start the app, select an item down the list (for example '05' minutes), then select the first item in the same dropdown (for example '00' minutes). The text in the dropdown control will now disappear.

    有人知道如何解决此问题吗?如果我将组合框项目面板的样式更改回CarouselPanel,则它可以工作(但当然具有无限循环)。

    Anyone know how to fix this? If I change the style of combobox itemspanel back to CarouselPanel it works (but with the infinite loop of course).

    推荐答案

    只需纠正使用VirtualizingStackPanel代替StackPanel可以解决此问题。
    我们必须设置尺寸原因,否则它将占用屏幕的所有宽度。

    Just corrected this issue using a VirtualizingStackPanel in place of a StackPanel. We had to set a size cause otherthise it take all the width of the screen.

    < VirtualizingStackPanel Horizo​​ntalAlignment = Center宽度= 150 />

    我们尚未尝试获得更灵活的解决方案,因为我们还不需要它

    We didn't try to get a more flexible solution because we don't need it yet

    希望它会帮助您

    这篇关于WinRT中组合框的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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