WPF弹出控件将立即关闭
我正在wpf中使用弹出控件。因此,当用户单击某个按钮时,弹出窗口应该被打开。 但实际上,弹出窗口打开但立即关闭。我尝试将StayOpen作为true使用,但当使用此选项时,尽管主窗口已关闭,但弹出窗口并未关闭 这是我的密码:WPF弹出控件将立即关闭,wpf,popup,Wpf,Popup,我正在wpf中使用弹出控件。因此,当用户单击某个按钮时,弹出窗口应该被打开。 但实际上,弹出窗口打开但立即关闭。我尝试将StayOpen作为true使用,但当使用此选项时,尽管主窗口已关闭,但弹出窗口并未关闭 这是我的密码: <Popup x:Name="Popup" Grid.Column="0" Grid.ColumnSpan="2" StaysOpen="False" Placement="RelativePoint" materialDesign:ShadowAssist.Shad
<Popup x:Name="Popup" Grid.Column="0" Grid.ColumnSpan="2" StaysOpen="False" Placement="RelativePoint" materialDesign:ShadowAssist.ShadowDepth="Depth5" Style="{x:Null}">
<Border Background="White" BorderBrush="#d2d9d4" BorderThickness="0.6" ClipToBounds="True">
<Grid>
<ListView MaxWidth="350" MaxHeight="450" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto"
VerticalContentAlignment="Stretch">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<!--Stuff-->
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Border>
</Popup>
我有什么遗漏吗?如何使弹出窗口保持打开状态,直到单击任何其他位置?我认为您需要将StaysOpen设置为true。我无法重现该问题。默认情况下,在设置
StaysOpen=false
之前,通过单击其他位置,弹出窗口也将保持打开状态。请发布一个。它是在几秒钟后关闭还是立即关闭?我猜您的代码背后是“按钮单击事件处理程序”。在第一行中,您将发送者转换为按钮。但在最后一行中,您将发件人作为边界。我想这是最重要的problem@Tronald,它会立即关闭。@Byoungsammon,是的,这是一个输入错误,虽然它是一个按钮,但问题仍然存在。如果我将StaysOpen设置为true,如果主窗口关闭,弹出窗口仍然不会关闭。
Popup.PlacementTarget = sender as Button;
Popup.IsOpen = true;
//RPopup.StaysOpen = true; Making popup open even after the main window is closed by clink somewhere on screen.
Popup.HorizontalOffset = ((Button)sender).ActualWidth + 10;