Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My solution to this was to create a label control with a "spring" like ability, so that it would fill the empty void with between the buttons on the toolbar, thus "right aligning" the toolbar's combobox (or any other control that needs "right-aligned).</p> <p>To do this, I created a WidthConverter, that would take the Actual Width of the ToolBar Control, and then subtract the the space needed needed to right align the combobox.:</p> <pre class="lang-cs prettyprint-override"><code>public class WidthConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return Math.Max(System.Convert.ToDouble(value) - System.Convert.ToDouble(parameter), 0.0); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>Then, I added a label control to the toolbar, placed to the left of the combobox you need right aligned. Bind the label's Width to the toolbar's ActualWidth and apply the WidthConverter:</p> <pre class="lang-cs prettyprint-override"><code>&lt;Label Width="{Binding Converter={StaticResource WidthConverter}, ElementName=toolBar1, Path=ActualWidth, ConverterParameter=50}" /&gt; </code></pre> <p>You will need to adjust the ConverterParameter to your specific needs until you get the desired "right align". A higher number provides more space for the combobox, whereas a lower number provides less space.</p> <p>Using this solution, the label will automatically resize whenever your toolbar resizes, making it appear that you have right aligned your combobox.</p> <p>There are two great benefit to this solution compared to adding a grid to the toolbar. The first is that if you need to use buttons on the toolbar, you won't lose the toolbar button styling. The second is that the overflow will work as expected if the toolbar length is reduced through window resizing. Individual buttons will go into the overflow as required. If the buttons are put into a a grid then the grid is put into the overflow taking all buttons with it.</p> <p>XAML of it in use:</p> <pre class="lang-xml prettyprint-override"><code>&lt;ToolBarPanel&gt; &lt;ToolBar Name="toolBar1"&gt; &lt;Button&gt; &lt;Image Source="save.png"/&gt; &lt;/Button&gt; &lt;Label Width="{Binding Converter={StaticResource Converters.WidthConverter}, ElementName=toolBar1, Path=ActualWidth, ConverterParameter=231}" HorizontalAlignment="Stretch" ToolBar.OverflowMode="Never"/&gt; &lt;Button&gt; &lt;Image Source="open.png"/&gt; &lt;/Button&gt; &lt;/ToolBar&gt; </code></pre> <p></p> <p>If you desire to always keep the last button on the toolbar, say a help button that you always want visible, add the attribute <em>ToolBar.OverflowMode="Never"</em> to its element.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload