简体   繁体   English

如何根据wpf toolbartray的可用空间调整宽度

[英]How to adjust width according to the space available for wpf toolbartray

I am using around 10-15 controls inside a WPF ToolbarTray control, Now the issue is while I am changing the resolution the controls present in it is not adjusting according to my need in case of Maximized window. 我在WPF ToolbarTray控件中使用了大约10-15个控件,现在问题是当我更改分辨率时,其中存在的控件在最大化窗口的情况下不根据我的需要进行调整。 For more detail I attached the screenshot below. 有关更多详细信息,请附上以下截图。

Toolbar Tray control appearing originally: 工具栏托盘控件最初出现: 工具栏托盘控件最初出现

Toolbar Tray need to appear like this(Which I am trying): 工具栏托盘需要显示如下(我正在尝试): 工具栏托盘需要显示如下

Can anybody tell me how to customize or what to do to achieve the second image like ToolbarTray.Any help is appreciated. 任何人都可以告诉我如何自定义或做什么来实现第二个图像像ToolbarTray.Any帮助表示赞赏。

Thanks in advance, 提前致谢,

Update: 更新:

<ToolBarTray Background="White">
    <ToolBar>

        <Button
        Width="50" Content="hi"/>
        <Button
        Width="100" Content="bye"/>
        <Button
        Content="welcome"/>
        <Button
        Width="20"/>
        <Button Content="Welcome"/>
        <Separator />
        <Button
        ToolBar.OverflowMode="Always" Content="save" />
        <Button
        ToolBar.OverflowMode="Always" Content="open" />
        <Button
        ToolBar.OverflowMode="AsNeeded" Content="bmp" />
    </ToolBar>
    <ToolBar HorizontalAlignment="Right">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="New Hi1"/>
            <Button Content="New Hi2"/>
            <Button Content="New Hi3"/>
        </StackPanel>
    </ToolBar>
</ToolBarTray>

As far as I know this is not possible out of the box, as the ToolbarTray is quite limited in its layout options. 据我所知,这是不可能开箱即用的,因为ToolbarTray的布局选项非常有限。

What you could do is wrap the Toolbars in a DockPanel to do the layouting. 你可以做的是将工具栏包装在DockPanel中进行布局。 But you are missing things then like changing toolbar positions via drag and drop. 但是你错过了一些东西,比如通过拖放更改工具栏位置。

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="50"></RowDefinition>
      <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
      <DockPanel Grid.Row="0" Background="White">
        <ToolBar DockPanel.Dock="Left">
         ....
      </ToolBar>
      <ToolBar DockPanel.Dock="Right" HorizontalAlignment="Right" HorizontalContentAlignment="Stretch">
        ...
      </ToolBar>
    </DockPanel>

I found the solution of my problem, now I am using a Grid inside the ToolBar control and adjusting the size of one column of the Grid(toolbarGrid) to make my controls as seen in my second Image. 我找到了我的问题的解决方案,现在我在ToolBar控件中使用Grid并调整Grid的一列(toolbarGrid)的大小来制作我的第二个Image中的控件。

Code: 码:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="0"/>
    <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

<Stackpanel
    Grid.Column ="0">

    <Button Width="50" Content="hi"/>
        <Button Width="100" Content="bye"/>
        <Button Content="welcome"/>
        <Button Width="20"/>
        <Button Content="Welcome"/>
        <Separator />
        <Button ToolBar.OverflowMode="Always" Content="save" />
        <Button ToolBar.OverflowMode="Always" Content="open" />
        <Button ToolBar.OverflowMode="AsNeeded" Content="bmp" />
</StackPanel>

    <ToolBarTray x:Name ="toolBarTray" Grid.Column ="1" HorizontalAlignment ="Right" IsLocked="True">

        <!--First Toolbar for the controls from Print to Zoom Control-->
        <ToolBar x:Name ="topToolBar" FocusVisualStyle="{x:Null}">
            <Grid x:Name="toolbarGrid">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button Content="New Hi1"/>
                <Button Content="New Hi2"/>
                <Button Content="New Hi3"/>
            </Grid>
        </ToolBar>
    </ToolBarTray>
</Grid>

简单的答案不是在你的应用程序的顶部“行”中绘制灰色背景?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM