Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was looking for a similar solution. I needed a group box style where the border was closed only when there is no header text. </p> <p>I'm not convinced it's the nicest solution, but it works fine...</p> <p>We have a converter (works with text only atm):</p> <pre><code>public class GroupBoxHeaderVisibilityConverter : IMultiValueConverter { #region IMultiValueConverter Members public object Convert(object[] values, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { ContentPresenter header = values[0] as ContentPresenter; if (header != null) { string text = header.Content as string; if (string.IsNullOrEmpty(text)) { return 0.0; } } return values[1]; } public object[] ConvertBack(object value, System.Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { throw new System.NotImplementedException(); } #endregion } </code></pre> <p>and the modifications to the groupbox style:</p> <pre><code>&lt;Border x:Name="Header" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Padding="3,1,3,0"&gt; &lt;Border.Tag&gt; &lt;MultiBinding Converter="{StaticResource GroupBoxHeaderVisibilityConverter}"&gt; &lt;Binding Path="Content" ElementName="groupBoxLabel" /&gt; &lt;Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" /&gt; &lt;/MultiBinding&gt; &lt;/Border.Tag&gt; &lt;Label x:Name="groupBoxLabel" FontSize="{StaticResource Fonts_SmallFontSize}" Foreground="{TemplateBinding Foreground}"&gt; &lt;ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True" /&gt; &lt;/Label&gt; &lt;/Border&gt; &lt;ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" /&gt; &lt;Border Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="3" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4"&gt; &lt;Border.OpacityMask&gt; &lt;MultiBinding Converter="{StaticResource BorderGapMaskConverter}" ConverterParameter="7"&gt; &lt;Binding ElementName="Header" Path="Tag" /&gt; &lt;Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" /&gt; &lt;Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" /&gt; &lt;/MultiBinding&gt; &lt;/Border.OpacityMask&gt; &lt;Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" /&gt; &lt;/Border&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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