我想在事件的页面中显示弹出窗口。我在页面的定义中添加了一个弹出窗口。它第一次正常工作。但由于Popup不是可视树的一部分,因此下次访问该页面时会再次创建弹出窗口。我怎么能避免这个?我知道的唯一选择是在代码隐藏中编写静态弹出窗口。但是有什么方法可以在xaml中做到这一点吗? (或可能在VM中)
这是我在XAML中的代码。
<Popup Grid.Row="2" x:Name="popup" IsOpen="{Binding VenueListOpen}">
<ScrollViewer Height="600" Margin="0,0,0,20" Background="#55000000">
<StackPanel Width="{Binding DeviceWidth}">
<ItemsControl ItemsSource="{Binding EventsList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="20,0" Background="{Binding BindsDirectlyToSource=True, Converter={StaticResource EventRowBackgroundConverter}}">
<TextBlock Margin="20,5" FontSize="30" Text="Metlife stadium" TextWrapping="Wrap"/>
<TextBlock Margin="20,5" Foreground="SkyBlue" Text="www.metlifestadium.com" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</Popup>
答案 0 :(得分:0)
当您进入页面时,如何将其Visible
属性设置为false或true?
答案 1 :(得分:0)
我找到了解决方法。可能有更好的解决方案,但这对我有用:
在代码后面,通过将绑定设置为null
来分离绑定。因此,每当您离开时,当前popup
将变为孤儿,当您再次访问该页面时,导航将创建新页面以及新弹出窗口。但这次只会显示新的弹出窗口,因为较旧的弹出窗口不与datacontext
绑定,因此对IsOpen
的绑定不会影响该弹出窗口的任何旧实例。