I have a textbox which I am trying to abide by the following rules:
Textbox must always be visible when it has focus
Textbox must always hide when it doesnt have focus AND it is empty
I have a dependency property setup which allows me to refocus the textbox, so that it shows. This works "one-way" in that I can focus a textbox that is collapsed and it shows. But once I move the focus out of the textbox (and its empty) it always remains.
How can I collapse the textbox, once focus is lost AND it is empty? (Note: I also want to SHOW the box, if text is entered (it is bound to other text boxes, which may have text entered, this is bound two-way).
<Style x:Key="textBoxHider" TargetType="{x:Type TextBox}" BasedOn="{StaticResource storyForgeTextBox}">
<Style.Triggers>
<Trigger Property ="IsMouseOver" Value="True">
<Setter Property= "BorderBrush" Value="LightCyan"/>
<Setter Property= "BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property= "BorderBrush" Value="LightSkyBlue"/>
<Setter Property= "BorderThickness" Value="2"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Text" Value=""></Condition>
<Condition Property="IsFocused" Value="False"></Condition>
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="Visibility" Value="Collapsed"></Setter>
</MultiTrigger.Setters>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsFocused" Value="True"></Condition>
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="Visibility" Value="Visible"></Setter>
</MultiTrigger.Setters>
</MultiTrigger>
</Style.Triggers>
</Style>
Edit: for clarity I have simplified it even further and its still not collapsing. Checking the value in Snoop. IsFocused is correctly being set to FALSE and TRUE when I am not focused/focused.
<Style x:Key="TextBoxHider" TargetType="{x:Type TextBox}" BasedOn="{StaticResource storyForgeTextBox}">
<Style.Triggers>
<Trigger Property ="IsMouseOver" Value="True">
<Setter Property= "BorderBrush" Value="LightCyan"/>
<Setter Property= "BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property= "BorderBrush" Value="LightSkyBlue"/>
<Setter Property= "BorderThickness" Value="2"/>
<Setter Property="Visibility" Value="Visible"></Setter>
</Trigger>
<Trigger Property="IsFocused" Value="False">
<Setter Property="Visibility" Value="Collapsed"></Setter>
</Trigger>
</Style.Triggers>
</Style>
edit:edit: I am now stumped. The border brush is being set to RED no problem. So the IsFocused is being fired, but its not collapsing the box?
<Style x:Key="storyForgeTextBoxHider" TargetType="{x:Type TextBox}" BasedOn="{StaticResource storyForgeTextBox}">
<Style.Triggers>
<Trigger Property ="IsMouseOver" Value="True">
<Setter Property= "BorderBrush" Value="LightCyan"/>
<Setter Property= "BorderThickness" Value="2"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property= "BorderBrush" Value="LightSkyBlue"/>
<Setter Property= "BorderThickness" Value="2"/>
<Setter Property="Visibility" Value="Visible"></Setter>
</Trigger>
<Trigger Property="IsFocused" Value="False">
<Setter Property="Visibility" Value="Collapsed"></Setter>
<Setter Property="BorderBrush" Value="Red"></Setter>
</Trigger>
</Style.Triggers>
</Style>