我有一个具有自定义样式的组合框,但下拉项呈现在屏幕左上角的 0,0 处。
<Style x:Key="CustomNetworkComboBox" TargetType="ComboBox">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="MinWidth" Value="175"/>
<Setter Property="Height" Value="22"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Visibility" Value="Hidden" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton Name="ToggleButton" Template="{StaticResource NetworkComboBoxToggleButton}" Grid.Column="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">
</ToggleButton>
<ContentPresenter Name="ContentSite" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="3,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBox x:Name="PART_EditableTextBox"
Foreground="{StaticResource Black13}" Style="{x:Null}" Template="{StaticResource ComboBoxTextBox}"
HorizontalAlignment="Left" VerticalAlignment="Center" Margin="3,3,23,3"
Focusable="True" Background="{x:Null}" Visibility="Hidden" IsReadOnly="True" BorderBrush="{x:Null}"/>
<Popup Name="PART_Popup" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide" Placement="Bottom" PlacementTarget="{Binding ElementName=ToggleButton}">
<Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder" Background="{StaticResource Black88}" BorderThickness="1" CornerRadius="1" BorderBrush="{StaticResource Black67}"/>
<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasItems" Value="false">
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
<Trigger SourceName="PART_Popup" Property="Popup.AllowsTransparency" Value="true">
<Setter TargetName="DropDownBorder" Property="Margin" Value="0,-1,0,0"/>
</Trigger>
<Trigger Property="IsEditable" Value="true">
<Setter Property="IsTabStop" Value="false"/>
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
<Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了谷歌搜索建议的几种不同的“解决方案”来解决这个问题,但到目前为止还没有奏效。
组合框位于网格内,该网格是列表视图中的项目,通过虚拟机填充数据。
<ComboBox Grid.Column="2" x:Name="Task" Margin="0,0,30,0" SelectedIndex="{Binding Path=IsCurrentComputer, Converter={StaticResource ComboboxIndexer}}" Style="{StaticResource CustomNetworkComboBox}"
TextBlock.FontFamily="/Views/Fonts/UniversLTStd-Ex.otf#Univers LT Std 53 Extended"
TextBlock.FontSize="12"
TextBlock.FontWeight="Normal"
TextBlock.Foreground="{StaticResource Black13}"
SelectedItem="{Binding Task}"
>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2558 次 |
| 最近记录: |