【问题标题】:The first item of ComboBox is not selectableComboBox 的第一项不可选择
【发布时间】: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


【解决方案1】:

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

Touch and Manipulation (MSDN)

基类 UIElement、UIElement3D 和 ContentElement 定义了您可以订阅的事件,以便您的应用程序响应触摸。当您的应用程序将触摸解释为不是操作对象时,触摸事件很有用。例如,允许用户用一根或多根手指进行绘图的应用程序将订阅触摸事件。

一些更有用的链接:

Why won't WPF controls work with manipulations?

UIElement.CaptureTouch Method

UIElement.ReleaseTouchCapture Method

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-01
    • 2023-03-21
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多