Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you found a bug, or at least a "weirdness" in the popup control - check this out:</p> <p>My initial thought was to simply Bind the Visibility of the Popup to the Host. This SHOULD work.</p> <pre><code> &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;Grid x:Name="Host" Width="200" Height="200" Background="Aqua"&gt; &lt;Popup IsOpen="True" Visibility="{Binding ElementName=Host, Path=Visibility}" Height="100" Width="100"&gt; &lt;Button Content="Some Button" Click="Button_Click"/&gt; &lt;/Popup&gt; &lt;/Grid&gt; &lt;/Grid&gt; </code></pre> <p>But it does not work. The "Host" grid disappears, but I still see the button. This confused me, so I fired up Silverlight Spy, and check this out - setting the Visibility of the Popup does NOT hide the button!</p> <p><a href="http://screencast.com/t/dHfiMjJus2D1" rel="nofollow">See Demo Video</a></p> <p>Anyway, in order to make this work, you just need to massage things a little bit in order tie the Host Visibility to the IsOpen property. I used a converter here:</p> <pre><code>&lt;UserControl.Resources&gt; &lt;Junk:VisibilityToBoolConverter x:Key="VisibilityToBoolConverter"/&gt; &lt;/UserControl.Resources&gt; &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;Grid x:Name="Host" Width="200" Height="200" Background="Aqua"&gt; &lt;Popup IsOpen="{Binding ElementName=Host, Path=Visibility, Converter={StaticResource VisibilityToBoolConverter}}" Height="100" Width="100"&gt; &lt;Button Content="Some Button" Click="Button_Click"/&gt; &lt;/Popup&gt; &lt;/Grid&gt; &lt;/Grid&gt; private void Button_Click(object sender, RoutedEventArgs e) { this.Host.Visibility = System.Windows.Visibility.Collapsed; } public class VisibilityToBoolConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return ((Visibility) value) == Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>That's working for me.</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