ComboBox的第一项是不可选择的

时间:2014-08-11 14:10:11

标签: c# xaml windows-store-apps

我在Windows应用程序中使用ComboBox以允许用户选择时间。

XAML

<ComboBox Name="timePeriodComboBox"
          HorizontalContentAlignment="Left"
          Width="200" Height="60"
          FontSize="30"
          HorizontalAlignment="Center" VerticalAlignment="Top"
          Grid.Column="2">
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical" />
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
</ComboBox>

C#

#region Initializing Frequency Combo Box

timePeriodComboBox.Items.Add("1 hour");
timePeriodComboBox.Items.Add("2 hours");
timePeriodComboBox.Items.Add("5 hours");
timePeriodComboBox.Items.Add("10 hours");
timePeriodComboBox.Items.Add("15 hours");
timePeriodComboBox.Items.Add("20 hours");
timePeriodComboBox.Items.Add("24 hours");
timePeriodComboBox.Items.Add("48 hours");
timePeriodComboBox.Items.Add("72 hours");
timePeriodComboBox.Items.Add("96 hours");

timePeriodComboBox.SelectedIndex = 0;

timePeriodComboBox.SelectionChanged += timePeriodComboBox_indexChanged;

#endregion
historyRequestModel.time = timePeriodComboBox.SelectedItem.ToString().Split(' ')[0];

问题是当我在HP Windows平板电脑上运行该应用程序时,它不允许我甚至触摸我的列表中的第一个项目(因为它不可点击或可选择,甚至突出显示,而其他人都这样做)(1小时) )。
但是,当我在可视工作室上运行模拟器或模拟器时,它可以正常工作。但其他项目是可选择的。

有人可以告诉我出了什么问题吗?如果我做错了什么或这是一个错误?说实话,我认为问题可能是本地机器使用鼠标并单击作为交互,而平板电脑使用触摸屏作为交互。这只是一个猜测,但我对组合框的旋转木马版本有类似的问题。它在本地计算机上运行良好,但随后在平板电脑上保留了重复值。所以这就是我关闭旋转木马的原因。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您需要订阅触摸事件,例如将触摸转换为适合您需求的内容。

Touch and Manipulation (MSDN)

  

基类UIElement,UIElement3D和ContentElement定义了您可以订阅的事件,以便您的应用程序响应触摸。当您的应用程序将触摸解释为操纵对象以外的其他内容时,触摸事件非常有用。例如,允许用户使用一个或多个手指绘制的应用程序将订阅触摸事件。

一些更有用的链接:

Why won't WPF controls work with manipulations?

UIElement.CaptureTouch Method

UIElement.ReleaseTouchCapture Method