工具栏按钮垂直列出 [英] Toolbar buttons are listed vertically

查看:67
本文介绍了工具栏按钮垂直列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中的工具栏出现问题,由于某种原因,工具栏上的按钮垂直显示在工具栏上,而不是通常的水平显示..

这是mainwindow.xaml文件中的代码片段,在其中声明了工具栏托盘和工具栏:

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:

<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:


<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! :)

推荐答案


在您的xaml资源中,未指定itemspanel模板,即它使用默认模板.如果必须水平显示内容,请尝试以下任一方法.

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.

<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


<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>


这篇关于工具栏按钮垂直列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆