05-01-2014 03:32 PM
I know there's a simple way to do this, but I have yet to find it.
How can I get the items in a WPF Legend to orient themselves horizontally instead of vertically?
Solved! Go to Solution.
05-01-2014 05:05 PM
For a standard items control, you would provide a custom items panel template to change orientation. The Legend does not expose a property to configure orientation, but it is easy to use a custom template to set this on the inner items control:
<ni:Legend.Template>
<ControlTemplate TargetType="{x:Type ni:Legend}">
<ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
<ItemsControl x:Name="PART_ItemsControl"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Foreground="{TemplateBinding Foreground}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</ControlTemplate>
</ni:Legend.Template>
05-01-2014 05:12 PM
Perfect, that did the trick!