1

ポップアップを使用すると、ぶらぶらしているようです。以下のコードでは、コントロール テンプレートをオーバーライドしてポップアップを textBox にアタッチし、TextBox にフォーカスがあるときにポップアップを表示します。画面上の次の要素にタブで移動すると、ポップアップは消えますが、別のアプリケーションに Alt キーを押して移動すると、ポップアップはフォアグラウンドに残ります。どうすればそれを取り除くことができますか?

<Window x:Class="DropDownPicker.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
      <StackPanel>
         <TextBox Text="hello">
         <TextBox.Style>
            <!-- Simple TextBox -->
            <Style
               TargetType="{x:Type TextBox}">
               <Setter
                  Property="KeyboardNavigation.TabNavigation"
                  Value="None" />
               <Setter
                  Property="FocusVisualStyle"
                  Value="{x:Null}" />
               <Setter
                  Property="AllowDrop"
                  Value="true" />
               <Setter
                  Property="Template">
                  <Setter.Value>
                     <ControlTemplate
                        TargetType="{x:Type TextBox}">
                        <Grid>
                           <Border
                              x:Name="Border"
                              Background="{DynamicResource WindowBackgroundBrush}"
                              BorderBrush="{DynamicResource SolidBorderBrush}"
                              BorderThickness="1"
                              Padding="2"
                              CornerRadius="2">

                              <Grid>
                              <!-- The implementation places the Content into the ScrollViewer. It must be named PART_ContentHost for the control to function -->
                              <ScrollViewer
                                 Margin="0"
                                 x:Name="PART_ContentHost"
                                 Style="{DynamicResource SimpleScrollViewer}"
                                 Background="{TemplateBinding Background}" />

                              <Popup
                                 x:Name="thePopup"
                                 IsOpen="False">
                                 <Border
                                    BorderBrush="Red"
                                    BorderThickness="5">
                                    <TextBlock
                                       Text="Hellssss" />
                                 </Border>
                              </Popup>
                              </Grid>
                           </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                              <Trigger
                                 Property="IsFocused"
                                 Value="True">
                                 <Setter
                                    TargetName="thePopup"
                                    Property="IsOpen"
                                    Value="True" />
                              </Trigger>
                        </ControlTemplate.Triggers>
                     </ControlTemplate>
                  </Setter.Value>
               </Setter>
            </Style>
         </TextBox.Style>
      </TextBox>
         <TextBox
            Text="ssss" />
       </StackPanel>
    </Grid>
</Window>
4

4 に答える 4

3

StaysOpenプロパティをに設定してみましたFalseか?

StaysOpenがデフォルトの場合True、コントロールのフォーカスがなくなるまで開いたままになります。その場合False、マウスまたはキーボードのイベントがPopupコントロールの外部で発生するまで開いたままになります。これは、Altキーを押したときに発生する可能性があります。希望どおりに動作させるには、少し調整する必要があるかもしれませんが、それが出発点になる場合があります。

于 2009-12-09T04:51:02.057 に答える
2

LostMouseCapture イベントをリッスンし、Popup の StaysOpen プロパティを false に設定しました

于 2011-01-05T17:54:31.410 に答える
0

これは仕様によるものです。ウィンドウフォーカス!=コントロールフォーカス。そうでない場合、ウィンドウから離れてタブで戻ったときに、カーソルが最初のコントロールに戻ります。ウィンドウがアクティブでないときにポップアップを非表示にする場合は、手動でこれを行う必要があります。

于 2009-12-09T04:45:29.617 に答える
0

同様の質問がここでも行われます: WPF Popup ZOrder

これをチェックして:

http://chriscavanagh.wordpress.com/2008/08/13/non-topmost-wpf-popup/

これがお役に立てば幸いです!!

于 2009-12-09T05:30:18.920 に答える