Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the adorner solution you linked to with a couple of changes, or you could do this with a style and converter.</p> <p><strong>Adorner solution</strong></p> <p>The adorner solution is more complex, but has a better interface and encapsulation. The changes you would need to make are straightforward but possibly difficult if you're not a WPF expert. They are:</p> <ol> <li><p>Recognize ComboBox as another special case (like TextBox). Subscribe to its SelectedItemChanged, and update adorner visibility using SelectedItem==null.</p></li> <li><p>Don't handle input events (HitTestVisible=False, Focusable=False, etc)</p></li> </ol> <p>In this case, your ComboBox style will be very simple, just setting the attached property.</p> <p> <p><strong>Style and converter</strong></p> <p>Doing it with a style and converter may be simpler for you. Here is the body of the converter:</p> <pre><code> object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value==null ? Visibility.Visible : Visibility.Hidden; } </code></pre> <p>Your style will replace the default ComboBox style and contain a copy of the ControlTemplate from the theme, wrapped with something like this (or use an adorner):</p> <pre><code> &lt;Style TargetType="{x:Class ComboBox}"&gt; &lt;Style.Setters&gt; &lt;Setter Property="local:MyInputPromptClass.PromptText" Value="SELECT an item" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Class ComboBox}"&gt; &lt;Grid&gt; ... existing XAML from theme ControlTemplate ... &lt;TextBlock Text="{Binding local:MyInputPromptClass.PromptText, RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding SelectedItem, Converter={x:Static local:MyInputPromptClass.Converter}, RelativeSource={RelativeSource TemplatedParent}}" HitTestVisible="False" Focusable="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style.Setters&gt; &lt;/Style&gt; </code></pre> <p>This solution is less satisfying than the other, since by copying the default ComboBox template from a theme you end up with an app that doesn't track the current Windows theme. It's possible to get around this using multiple ControlTemplates along with StaticResource and some tricky binding, but at that point I would recommend just using the adorner and attached property.</p>
    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. VO
      singulars
      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