.net - 如何在 UWP 中创建响应式组合框?
问题描述
我正在尝试构建一个响应组合框,即:
- 当项目列表不适合父级的宽度时 => 带有下拉菜单的组合框
- 当项目列表适合父项的宽度时 => 没有下拉列表的组合框(如列表框)
对于案例编号 2,我正在尝试修改组合框的样式(最小示例):
<Style x:Key="ComboBoxFlatStyle" TargetType="ComboBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<CarouselPanel/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<StackPanel>
<ContentPresenter x:Name="ContentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Grid.Row="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
</ContentPresenter>
<FontIcon x:Name="DropDownGlyph" AutomationProperties.AccessibilityView="Raw" Grid.Column="1" Foreground="{ThemeResource ComboBoxDropDownGlyphForeground}" FontSize="12" FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="" HorizontalAlignment="Right" IsHitTestVisible="False" Margin="0,10,10,10" Grid.Row="1" VerticalAlignment="Center"/>
**<Popup x:Name="Popup">**
<Border x:Name="PopupBorder" BorderBrush="{ThemeResource ComboBoxDropDownBorderBrush}" BorderThickness="{ThemeResource ComboBoxDropdownBorderThickness}" Background="{ThemeResource ComboBoxDropDownBackground}" HorizontalAlignment="Stretch" Margin="0,-1,0,-1" >
<ScrollViewer x:Name="ScrollViewer" AutomationProperties.AccessibilityView="Raw" BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}" Foreground="{ThemeResource ComboBoxDropDownForeground}" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" MinWidth="{Binding TemplateSettings.DropDownContentMinWidth, RelativeSource={RelativeSource Mode=TemplatedParent}}" VerticalSnapPointsType="OptionalSingle" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" VerticalSnapPointsAlignment="Near" ZoomMode="Disabled">
<ItemsPresenter Margin="{ThemeResource ComboBoxDropdownContentMargin}"/>
</ScrollViewer>
</Border>
</Popup>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如果我删除弹出元素,则不会触发“SelectedItem”(在点击事件上始终为空),selectedItem 以某种方式连接到弹出元素。有没有其他方法可以做到这一点?
解决方案
推荐阅读
- access-token - AcquireTokenSilentAsync 不起作用
- php - PHP在字符限制上剪切字符串
- c# - MongoDB C# 驱动程序和过滤位置运算符 $[
] 使用类型化 API - python - 根据特定列中的不同范围值对多个数据帧进行切片,并将它们分类到新列中
- swift - locationManager.startMonitoring(for: region) 错误?
- sql - SQL - 为所有符合条件的 id 查找 id
- javascript - 使用 react/redux 搜索/过滤列表
- excel-formula - 多张纸的计数
- ssis - 如何比较两个表的行数,如果计数匹配,则如果不匹配则可以,这将重新启动 SSIS 包
- python - 在 Python 中存储常量的位置