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?

Thank!

MainWindow view:

<Grid x:Name="LayoutRoot">
    <ScrollViewer>
        <local:ControlView/>

    </ScrollViewer>
</Grid>

      

Resource Dictionary:

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

      

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">
                                     <!--BINDING--> 
                                     <Label Content="Hello World!"/>                             
                                    </ScrollViewer>
                                </GroupBox>
                            </Border>
                        </Popup>
                        <ContentPresenter Content="{Binding testBinding}"
                                          VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        </ContentPresenter>
                    </StackPanel>
</Grid>

      

+3


source to share


1 answer


Try the following:



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

      

+1


source







All Articles