Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use an attached property to simplify adding group styles:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Style TargetType="MenuItem"&gt; &lt;Setter Property="b:GroupStyleEx.Append"&gt; &lt;Setter.Value&gt; &lt;GroupStyle .. /&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;!-- you can add as many as you like... --&gt; &lt;Setter Property="b:GroupStyleEx.Append"&gt; &lt;Setter.Value&gt; &lt;!-- second group style --&gt; &lt;GroupStyle .. /&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>Here's the code for the attached property:</p> <pre class="lang-cs prettyprint-override"><code>using System; using System.Windows; using System.Windows.Controls; namespace Util { public static class GroupStyleEx { public static readonly DependencyProperty AppendProperty = DependencyProperty.RegisterAttached("Append", typeof (GroupStyle), typeof (GroupStyleEx), new PropertyMetadata(AppendChanged)); public static GroupStyle GetAppend(DependencyObject obj) { return (GroupStyle) obj.GetValue(AppendProperty); } public static void SetAppend(DependencyObject obj, GroupStyle style) { obj.SetValue(AppendProperty, style); } private static void AppendChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var itemsControl = d as ItemsControl; if (itemsControl == null) throw new InvalidOperationException("Can only add GroupStyle to ItemsControl"); var @new = e.NewValue as GroupStyle; if (@new != null) itemsControl.GroupStyle.Add(@new); } } } </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