1

我有以下弹出窗口:

<Popup Name="popupBind"
               AllowsTransparency="True"
               Helpers:FocusHelper.IsFocused="{Binding RelativeSource={RelativeSource Self},
                                                       Path=IsOpen,
                                                       Mode=OneWay}"
               HorizontalOffset="-30"
               IsOpen="{Binding IsBindingBegun,
                                Mode=TwoWay}"
               Placement="Bottom"
               PlacementTarget="{Binding ElementName=bindButton}"
               StaysOpen="False"
               >
            <Border Background="{DynamicResource {x:Static Styles:CommonStyles.ButtonsPanelBackgroundKey}}"
                    BorderBrush="Black"
                    BorderThickness="1"
                    Padding="0">
                <StackPanel HorizontalAlignment="Stretch">

                    <StackPanel.Resources>
                        <TemplateSelectors:VersionRangeDataTemplateSelector x:Key="VersionRangeDataTemplateSelector" />
                        <Converters:RangeToVisibilityConverter x:Key="RangeToVisibilityConverter" />
                    </StackPanel.Resources>

                    <StackPanel Margin="5,5,5,2"
                                HorizontalAlignment="Stretch"
                                Orientation="Horizontal">

                        <StackPanel.Resources>
                            <Style TargetType="Button">
                                <Setter Property="Margin" Value="5" />
                            </Style>
                        </StackPanel.Resources>

                        <Button Command="{Binding BindCommand}"
                               >
                        </Button>
                        <Button Command="{Binding BindCommand}"
                                >
                        </Button>
                        <Button Command="{Binding BindCommand}"
                                >
                        </Button>
                        <Button Command="{Binding BindCommand}"
                                >
                        </Button>
                    </StackPanel>

                    <ItemsControl Margin="10,2,5,5"
                                  Focusable="False"
                                  Grid.IsSharedSizeScope="True"
                                  ItemTemplateSelector="{StaticResource VersionRangeDataTemplateSelector}"
                                  ItemsSource="{Binding Path=VersionsVm.TempRanges}">
                        <ItemsControl.Resources>
                            <Style TargetType="CheckBox">
                                <Setter Property="VerticalAlignment" Value="Center" />
                                <Setter Property="Padding" Value="0" />
                            </Style>

                            <Style TargetType="TextBlock">
                                <Setter Property="FontSize" Value="14" />
                                <Setter Property="VerticalAlignment" Value="Center" />
                                <Setter Property="Padding" Value="2" />
                            </Style>

                            <DataTemplate x:Key="TwoDistinctVersionsRangeTemplateKey">
                                <Grid Margin="2,4" HorizontalAlignment="Stretch">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="_1" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="_2" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="_3" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="_4" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="_5" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="_6" />
                                        <ColumnDefinition Width="Auto" SharedSizeGroup="_7" />
                                    </Grid.ColumnDefinitions>

                                    <CheckBox Grid.Column="0" IsChecked="{Binding IncludeStartEdge, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                                    <TextBlock Grid.Column="1" Margin="2,0,5,0">
                                        <TextBlock.Style>
                                            <Style TargetType="TextBlock">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IncludeStartEdge}" Value="True">
                                                        <Setter Property="Text" Value="[" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding IncludeStartEdge}" Value="False">
                                                        <Setter Property="Text" Value="(" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>

                                    <TextBlock Grid.Column="2"
                                               HorizontalAlignment="Left"
                                               Text="{Binding FromVersionName}"
                                               TextAlignment="Left" />

                                    <TextBlock Grid.Column="3"
                                               Width="10"
                                               Margin="5,0"
                                               HorizontalAlignment="Center"
                                               Text="-"
                                               TextAlignment="Center" />

                                    <TextBlock Grid.Column="4"
                                               HorizontalAlignment="Left"
                                               Text="{Binding ToVersionName}"
                                               TextAlignment="Left" />

                                    <TextBlock Grid.Column="5" Margin="5,0,2,0">
                                        <TextBlock.Style>
                                            <Style TargetType="TextBlock">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IncludeEndEdge}" Value="True">
                                                        <Setter Property="Text" Value="]" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding IncludeEndEdge}" Value="False">
                                                        <Setter Property="Text" Value=")" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>

                                    <CheckBox Grid.Column="6" IsChecked="{Binding IncludeEndEdge, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                </Grid>
                            </DataTemplate>

                            <DataTemplate x:Key="FixedVersionRangeTemplateKey">
                                <StackPanel>
                                    <TextBlock Margin="2,4"
                                               HorizontalAlignment="Left"
                                               VerticalAlignment="Center"
                                               Text="{Binding FromVersionName}"
                                               TextAlignment="Left" />
                                    <StackPanel>
                                        <StackPanel.Visibility>
                                            <MultiBinding Converter="{StaticResource RangeToVisibilityConverter}">
                                                <MultiBinding.Bindings>
                                                    <Binding />
                                                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=UserControl}" />
                                                </MultiBinding.Bindings>
                                            </MultiBinding>
                                        </StackPanel.Visibility>
                                        <RadioButton Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                                      AncestorType=UserControl},
                                                                       Path=DataContext.VersionsVm.ChangeTempRangeTypeCommand}"
                                                                                                              Content="&lt;" />
                                        <RadioButton Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                                      AncestorType=UserControl},
                                                                       Path=DataContext.VersionsVm.ChangeTempRangeTypeCommand}"                                                         
                                                     Content="&lt;=" />
                                        <RadioButton Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                                      AncestorType=UserControl},
                                                                       Path=DataContext.VersionsVm.ChangeTempRangeTypeCommand}"                                                         
                                                     Content="="
                                                     IsChecked="True" />
                                        <RadioButton Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                                      AncestorType=UserControl},
                                                                       Path=DataContext.VersionsVm.ChangeTempRangeTypeCommand}"
                                                                                                              Content="&gt;=" />
                                        <RadioButton Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                                      AncestorType=UserControl},
                                                                       Path=DataContext.VersionsVm.ChangeTempRangeTypeCommand}"
                                                                                                              Content="&gt;" />
                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </ItemsControl.Resources>
                    </ItemsControl>
                </StackPanel>
            </Border>
        </Popup>

我有一个非常奇怪的问题。
当我点击 Tab 时,左或右焦点离开弹出窗口并转到父窗口。Popus 保持打开状态。
我不知道为什么会这样。但我的键盘导航坏了。
我唯一可以怀疑的原因是 Popup 的父级是在 winforms ElementHost 中托管的 UserControl。
我不知道如何调试这个问题,所以我很感激任何有用的提示。
先感谢您。

4

1 回答 1

3

对 IsOpen 进行绑定可以覆盖 StaysOpen 行为。如果没有看到更多内容,我无法判断,但是如果 IsOpen 绑定True从其源中持久保存一个值,那么无论焦点发生什么情况,都会使 Popup 保持打开状态。

于 2013-01-18T19:20:21.773 回答