2009-03-09 12 views
2

私はComboBoxの上に積み重ねられたテキストボックスを持っています。 TextBoxは、フォーカスを取得すると(アニメーションを介して)高くなり、フォーカスが失われたときに戻るように戻ります。コンボボックスが動いているときにWPFコンボボックスのポップアップが外れないようにするにはどうすればよいですか?

問題は、テキストボックスがコンボボックスにフォーカスを失ったときに開始されます。これが起こると、選択ポップアップ(ドロップダウンした部分)は、期待どおりComboBoxのすぐ下に表示されますが、ComboBoxが上に移動すると(上のTextBoxが縮小しているため)、選択ポップアップは追従しません。 ComboBoxから切り離されたように見えます。

おそらくこれは、選択ポップアップ(すべてのポップアップなど)がTextBoxおよびComboBoxと同じビジュアルツリーの一部ではないため、アニメーションの進行に合わせてそのレイアウトが再計算されないためです。

どのように私のコンボボックス全体を保持できますか?

以下は、これを再現するためにXamlPadに貼り付けるスニペットです。どんな助けでも大歓迎です!

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > 
    <StackPanel Width="100" Orientation="Vertical"> 
    <TextBox Height="19"> 
     <TextBox.Triggers> 
     <EventTrigger RoutedEvent="UIElement.GotFocus"> 
      <EventTrigger.Actions> 
      <BeginStoryboard> 
       <Storyboard TargetProperty="Height"> 
       <DoubleAnimation From="19" To="100" Duration="0:0:0.2"/> 
       </Storyboard> 
      </BeginStoryboard> 
      </EventTrigger.Actions> 
     </EventTrigger> 
     <EventTrigger RoutedEvent="UIElement.LostFocus"> 
      <EventTrigger.Actions> 
      <BeginStoryboard> 
       <Storyboard TargetProperty="Height"> 
       <DoubleAnimation From="100" To="19" Duration="0:0:0.2"/> 
       </Storyboard> 
      </BeginStoryboard> 
      </EventTrigger.Actions> 
     </EventTrigger> 
     </TextBox.Triggers> 
    </TextBox> 
    <ComboBox> 
     <ComboBoxItem>Item 1</ComboBoxItem> 
     <ComboBoxItem>Item 2</ComboBoxItem> 
    </ComboBox> 
    </StackPanel> 
</Page> 

これは、Microsoft Connectサイトでバグとして掲載されました:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=422254

答えて

0

私は回避策はここにあることを知りません。しかし、私はこれをバグとして絶対に分類し、Microsoft Connectサイトに提出します。

+0

: https://connect.microsoft.com/VisualStudio/フィードバック/ ViewFeedback.aspx?FeedbackID = 422254 – nollidge

0

これは非常にラメの回避策ですが、テキストボックスに代わりのコンボボックスに、コンボボックスのポップアップオープン相対を作ることができる:

完了
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <StackPanel Width="100" Orientation="Vertical"> 
     <TextBox x:Name="myTextBox" Height="19"> 
      <TextBox.Triggers> 
       <EventTrigger RoutedEvent="UIElement.GotFocus"> 
        <EventTrigger.Actions> 
         <BeginStoryboard> 
          <Storyboard TargetProperty="Height"> 
           <DoubleAnimation Duration="0:0:0.2" From="19" To="100"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger.Actions> 
       </EventTrigger> 
       <EventTrigger RoutedEvent="UIElement.LostFocus"> 
        <EventTrigger.Actions> 
         <BeginStoryboard> 
          <Storyboard TargetProperty="Height"> 
           <DoubleAnimation Duration="0:0:0.2" From="100" To="19"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger.Actions> 
       </EventTrigger> 
      </TextBox.Triggers> 
     </TextBox> 
     <ComboBox> 
      <ComboBox.Resources> 
       <Style TargetType="{x:Type Popup}"> 
        <Setter Property="PlacementTarget" Value="{Binding ElementName=myTextBox}"/> 
        <Setter Property="PlacementRectangle" Value="0,39,0,0"/> 
       </Style> 
      </ComboBox.Resources> 
      <ComboBoxItem>Item 1</ComboBoxItem> 
      <ComboBoxItem>Item 2</ComboBoxItem> 
     </ComboBox> 
    </StackPanel> 
</Page> 
関連する問題