如何根据wpf工具栏托盘的可用空间调整宽度
我在 WPF ToolbarTray 控件内使用大约 10-15 个控件,现在的问题是,当我更改分辨率时,其中存在的控件在最大化窗口的情况下不会根据我的需要进行调整。有关更多详细信息,我附上了下面的屏幕截图。
最初出现的工具栏托盘控件:
工具栏托盘需要像这样显示(我正在尝试):
谁能告诉我如何自定义或如何实现像 ToolbarTray 这样的第二个图像。任何帮助表示赞赏。
提前致谢,
更新:
<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>
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. 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.
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,这是不可能的,因为 ToolbarTray 的布局选项非常有限。
您可以做的是将工具栏包装在 DockPanel 中以进行布局。但是您错过了一些事情,例如通过拖放更改工具栏位置。
As far as I know this is not possible out of the box, as the ToolbarTray is quite limited in its layout options.
What you could do is wrap the Toolbars in a DockPanel to do the layouting. But you are missing things then like changing toolbar positions via drag and drop.
我找到了问题的解决方案,现在我在 ToolBar 控件内使用网格并调整网格(toolbarGrid)一列的大小以使我的控件如第二个图像中所示。
代码:
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.
Code:
简单的答案不是在应用程序的顶部“行”中绘制灰色背景?
The simple answer wouldn't be to draw a grey background in the top 'line' of your App ??