Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with a toolbar in my application, the buttons on the toolbar are for some reason presented vertically on the toolbar and not horizontally as they normally are..

This is a snippet from the mainwindow.xaml file there the toolbartray and toolbar are declared:

XML
<ToolBarTray Orientation="Horizontal" DockPanel.Dock="Top"  x:Name="toolBarTray" VerticalAlignment="Top" Background="{DynamicResource MyBrightBlueSolidBrush1}">
       <ToolBar Visibility="{Binding Path=ActiveConfigWorkspace.HasCommands, Converter={StaticResource VisibilityOfBool}}" IsEnabled="True" IsHitTestVisible="True" x:Name="configToolBar" Style="{DynamicResource MyMenuToolBarWithWrapStyle}" Background="{DynamicResource MyBrightBlueSolidBrush1}">
        <ContentControl
                Content="{Binding Path=ActiveConfigWorkspace.Commands}"
                ContentTemplate="{StaticResource WorkspaceMenuTemplate}"
            />
    </ToolBar>
    </ToolBarTray>


and this is a snippet form a resource dictionary where content template for the toolbar content is declared:


XML
<DataTemplate x:Key="WorkspaceMenuTemplate" DataType="x:Type vm:WorkspaceViewModel">
    <ItemsControl ItemsSource="{Binding}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Button Command="{Binding Path=Command}"
                        Content="{Binding Path=DisplayName, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"
                        Style="{DynamicResource MyButtonStyle}" Background="{DynamicResource MyBrightBlueSolidBrush2}" BorderBrush="{DynamicResource MyDarkBlueSolidBrush}" BorderThickness="0.5,0.5,0.5,0.5">
                </Button>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</DataTemplate>


I can not figure out what is causing the buttons to be listed vertically, so any help on this would be highly apreciated! :)
Posted

1 solution

Hi,
In your xaml resource, the itemspanel template is not specified, that is it uses the default template. If you have to display the contents horizontally try either of the following.

XML
<DataTemplate x:Key="WorkspaceMenuTemplate" DataType="x:Type vm:WorkspaceViewModel">
        <ItemsControl ItemsSource="{Binding}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Command="{Binding Path=Command}"
                        Content="{Binding Path=DisplayName, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"
                        Style="{DynamicResource MyButtonStyle}" Background="{DynamicResource MyBrightBlueSolidBrush2}" BorderBrush="{DynamicResource MyDarkBlueSolidBrush}" BorderThickness="0.5,0.5,0.5,0.5">
                    </Button>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DataTemplate>



OR


XML
<DataTemplate x:Key="WorkspaceMenuTemplate" DataType="x:Type vm:WorkspaceViewModel">
        <ItemsControl ItemsSource="{Binding}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Command="{Binding Path=Command}"
                        Content="{Binding Path=DisplayName, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"
                        Style="{DynamicResource MyButtonStyle}" Background="{DynamicResource MyBrightBlueSolidBrush2}" BorderBrush="{DynamicResource MyDarkBlueSolidBrush}" BorderThickness="0.5,0.5,0.5,0.5">
                    </Button>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DataTemplate>
 
Share this answer
 
Comments
Frode Jensen 24-Jun-10 3:49am    
Thank you for the reply, I'm kinda new to WPF and have not totally controll over the binding template mechanism :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900