【问题标题】:How to adjust width of combo box popup in UWP App如何在 UWP App 中调整组合框弹出框的宽度
【发布时间】:2016-11-09 16:59:11
【问题描述】:

我正在使用组合框并想调整组合框的弹出(下拉)宽度。我正在使用 xaml 和 C#。

【问题讨论】:

  • 你的代码在哪里?没有看到任何代码的人怎么能回答这个问题?

标签: win-universal-app uwp uwp-xaml


【解决方案1】:

您可以将弹出窗口的 Width 属性绑定到组合框的“ActualWidth”属性。

但如果您想为其编写代码,也可以这样做:

TestPopUp.Width = TestComboBox.ActualWidth;

【讨论】:

    【解决方案2】:

    只需为组合框创建一个新样式并应用它。您可以在此处找到 UWP 组合框的默认模板:https://msdn.microsoft.com/en-us/library/windows/apps/mt299116.aspx

    特别注意调整这个元素的样式 <Popup x:Name="Popup">

    <UserControl.Resources>
        <Style x:Key="MyComboBoxStyle" TargetType="ComboBox">
           ...
           <Popup x:Name="Popup" Width="300">
           ...
        </Style>
    </UserControl.Resources>
    
    <ComboBox Style={StaticResource MyComboBoxStyle} />
    

    【讨论】:

    • 我同意修改组合框模板样式的部分,但是为什么要把样式放在UserControl的资源中呢?您是否建议OP需要创建一个UserControl来修改样式并使ComboBox成为一个新控件?
    猜你喜欢
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2010-11-27
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多