CheckListBox does not allow vertical item layout with horizontal overflow
cwenger opened this issue · 1 comments
I would like a CheckListBox
that stacks items vertically until the space is exhausted, and then continues at the top-right. For example, I can do the following with a plain ListBox
in native WPF:
<ListBox Height="50" Width="100" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem Content="A" />
<ListBoxItem Content="B" />
<ListBoxItem Content="C" />
</ListBox>
When I try the same with a CheckListBox
, it seems to ignore the disabling of the vertical scroll bar (the ItemsPanel
seems to be followed because changing the WrapPanel
orientation has an effect):
<xceed:CheckListBox Height="50" Width="100" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<xceed:CheckListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</xceed:CheckListBox.ItemsPanel>
<ListBoxItem Content="A" />
<ListBoxItem Content="B" />
<ListBoxItem Content="C" />
</xceed:CheckListBox>
Is this a bug? Is there any way to achieve the desired item layout with a CheckListBox
?
Hi,
For now, there is no easy way since the CheckListBox's default ControlTemplate uses an ItemsPresenter.
You best option would be to redefine the ControlTemplate to use a WrapPanel. Maybe something like:
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:CheckListBox}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <ScrollViewer Padding="{TemplateBinding Padding}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"> <StackPanel> <prim:SelectAllSelectorItem x:Name="PART_SelectAllSelectorItem" Content="{TemplateBinding SelectAllContent}" Visibility="{Binding IsSelectAllActive, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter}}" /> <!--<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>--> <WrapPanel IsItemsHost="True" Orientation="Vertical" Height="{TemplateBinding Height}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </StackPanel> </ScrollViewer> </Border> </ControlTemplate> </Setter.Value> </Setter>
Thanks