Popup does not close on scroll

I have a textbox where when it has focus, a popup appears below it. But when the popup is open and I scroll through it, it seems to stay in the same place where it was opened. I need help figuring out how the popup appears below the textbox when scrolling. How can I do this in xaml?


MainWindow view:

<Grid x:Name="LayoutRoot">



Resource Dictionary:

<Style TargetType="{x:Type Popup}">
        <DataTrigger Binding="{Binding ElementName=txtTest, Path=IsKeyboardFocused}" Value="True">
            <Setter Property="IsOpen" Value="True" />
        <DataTrigger Binding="{Binding ElementName=txtTest, Path=IsKeyboardFocused }" Value="False">
            <Setter Property="IsOpen" Value="False" />
<Style x:Key="BorderStyle" TargetType="{x:Type Border}">
    <Setter Property="Background" Value="LemonChiffon"/>
    <Setter Property="Padding" Value="5"/>


UserControl View:

<Grid x:Name="LayoutRoot">
        <StackPanel Grid.Row="1" Grid.Column="4" Orientation="Vertical">
                         <Button Content="Button" Width="100" Height="100"/>
                         <Button Content="Button" Width="100" Height="100"/>
                         <TextBox x:Name="txtTest" HorizontalAlignment="Stretch"/>

                        <Popup Name="TestPopup" StaysOpen="True"
                           PlacementTarget="{Binding ElementName=txtTest}"
                           AllowsTransparency="True" Placement="{Binding ElementName=txtTest}">
                            <Border Style="{DynamicResource BorderStyle}">
                                <GroupBox Header="Test Popup">
                                    <ScrollViewer Margin="0,2,0,0" VerticalScrollBarVisibility="Hidden">
                                     <Label Content="Hello World!"/>                             
                        <ContentPresenter Content="{Binding testBinding}"
                                          VerticalAlignment="Stretch" HorizontalAlignment="Stretch">



source to share

1 answer

Try the following:

<Style TargetType="{x:Type Popup}">
        Value="{Binding IsKeyboardFocusedWithin, ElementName=txtTest, Mode=OneWay}"/>




All Articles