I have spent all day looking for a way to display a default string of text on a ComboBox
and the closest I managed to find that worked was an example that uses
Based on your posted code I'm assuming your using the Behavior
from Here
Now if you download the sample zip in the above Link, you got 5 files that give you this set of Behavior
's(found in the Behavior
folder).
Edit TextBlockAdorner.cs
In the constructor just after the line
m_TextBlock = new TextBlock { Style = labelStyle, Text = label };
add
m_TextBlock.DataContext = adornedElement;
Now in your Style
setter switch your Binding
to
<Setter Property="TextBlock.Visibility"
Value="{Binding DataContext.Visible}" />
and you should be done.
Side-Notes:
System.Windows.Visibility
in your VM. Keep Visibility
property in the VM as a bool
and when your Binding
it in xaml use a BooleanToVisibilityConverter
(available directly in xaml. You do not have to create one)Style
's get into the habit of specifying a Type="..."
. It not only helps identify at a glance which Style
's relate to what but also saves some redundant type qualification for each of your setter properties.so something like
<Setter Property="FrameworkElement.Opacity"
Value="0.8" />
will be
<Style x:Key="watermarkLabelStyle"
TargetType="{x:Type TextBlock}">
...
<Setter Property="Opacity"
Value="0.8" />
Visible
while it's private back-end is _visibile
.