Further investigation showed that in order to do this I need to set the width of a Grid
within the ToolBar
, or as Chris Nicol said, a DockPanel
within the ToolBar
dynamically to that of the width of the Toolbar
using RelativeSource
.
However, that did not feel like a clean solution. It is quite complicated to get the Toolbar
to update correctly on resizing. So instead I found somewhat of a hack that looks, and operates cleaner by adding an external Grid.
<Grid>
<ToolBar Height="38" VerticalAlignment="Top" Grid.Row="1">
<Button HorizontalAlignment="Left" Width="50" VerticalAlignment="Stretch"/>
<Button HorizontalAlignment="Left" Width="50" VerticalAlignment="Stretch"/>
</ToolBar>
<ComboBox Margin="0,0,15,0" Width="120" HorizontalAlignment="Right" Grid.Row="1"/>
</Grid>
Since all of my elements are on a Grid, I can place my ComboBox
on top of the ToolBar
by assigning it's Grid.Row
to the same row as the toolbar. After setting my Margins
to pull the ComboBox
over slightly as not to interfere with looks, it operates as needed with no bugs. Since the only other way I found to do this was setting a DockPanel/Grid's Width property dynamically, I actually feel like this is the cleaner more efficient way to do it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…