Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is as simple as this:</p> <pre><code>&lt;Border x:Name="Border1" ... Visibility="Visible" ... /&gt; ... &lt;Trigger SourceName="ListBox1" Property="ListBox.SelectedIndex" Value="-1"&gt; &lt;Setter TargetName="Border1" Property="UIElement.Visibilty" Value="Hidden" /&gt; &lt;/Trigger&gt; </code></pre> <p><strong>Update</strong></p> <p>I see from the new code you posted that you're trying to use a trigger directly on the ListBox. The trigger must be in a ControlTemplate to use SourceName. If your UI is done with "custom controls" (my preference), you will already have a ControlTemplate to put it in. If not, you can easily add one by wrapping your XAML in a generic "ContentControl" (base class, not any subclass) and setting its template, like this:</p> <pre><code>&lt;Window ...&gt; ... &lt;ContentControl&gt; &lt;ContentControl.Template&gt; &lt;ControlTemplate TargetType="{x:Type ContentControl}"&gt; &lt;Grid&gt; ... &lt;ListBox x:Name="ListBox1" ... /&gt; ... &lt;Border x:Name="Border1"&gt; ... &lt;/Border&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger SourceName="ListBox1" Property="ListBox.SelectedIndex" Value="-1"&gt; &lt;Setter TargetName="Border1" Property="UIElement.Visibility" Value="Hidden" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/ContentControl.Template&gt; &lt;/ContentControl&gt; ... &lt;/Window&gt; </code></pre> <p>A better solution would probably be to use custom controls. Using a binding with a converter is possible but not as elegant IMHO.</p>
 

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