Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Horizontal Orientation for WPF Legend items?

Solved!
Go to solution

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?

0 Kudos
Message 1 of 3
(5,871 Views)
Solution
Accepted by topic author shansen1

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>

~ Paul H
Message 2 of 3
(5,863 Views)

Perfect, that did the trick!

0 Kudos
Message 3 of 3
(5,859 Views)