【发布时间】:2014-08-11 14:10:11
【问题描述】:
我在我的 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 小时) ).
但是,当我在视觉工作室上运行模拟器或模拟器时,它可以正常工作。但其他项目是可选的。
谁能告诉我哪里出了问题,我做错了什么还是这是一个错误?老实说,我认为问题可能是本地机器使用鼠标和点击作为交互,而平板电脑使用触摸屏作为交互。这只是一个猜测,但我对组合框的轮播版本也有类似的问题。它在本地机器上运行良好,但在平板电脑上它不断复制值。所以这就是我关闭轮播的原因。有什么想法吗?
【问题讨论】:
-
请定义“无法选择”并显示
timePeriodComboBox_indexChanged事件处理程序。 -
我将您的代码复制到一个新的解决方案中,它运行良好。
-
看来你可以选择第一项没有问题,(例如,
timePeriodComboBox.SelectedIndex = 0)。如果您无法“选择”此项,那么您将遇到某种编译错误。它会认为 CodeCaster 的评论是最重要的,显示你的indexChanged事件。 -
我已经编辑了我的问题
-
@user3929914
timePeriodComboBox_indexChanged实现在哪里?显示它。
标签: c# xaml windows-store-apps