2013-04-26 62 views
1

使用概念发现here on StackOverflow请注意,ToggleButton.IsHitTestVisible绑定到Popup.IsOpen,与StaysOpen="False"这应该意味着触摸任何地方Popup会导致它关闭。但是...WPF弹出ISOPEN问题

按照预期,在ItemsControl上触摸/点击ListBoxItem将不会按照预期关闭Popup。触摸Popup其他任何地方关闭它。根据如何设置,这似乎没有加起来。

<Grid ClipToBounds="True"> 
    <Border Name="Root"> 
     <ToggleButton x:Name="PART_Toggle" 
        ClickMode="Release" 
        IsHitTestVisible="{Binding ElementName=PART_Popup, 
              Path=IsOpen, 
              Mode=OneWay, 
              Converter={StaticResource BooleanInverter}}"/> 
    </Border> 
    <Popup x:Name="PART_Popup" 
      IsOpen="{Binding ElementName=PART_Toggle, 
          Path=IsChecked}" 
      PlacementTarget="{Binding ElementName=PART_Toggle}" 
      StaysOpen="False"> 
     <Grid Background="Transparent"> 
      <Grid> 
       <!-- Anything here (outside of the Item) --> 
       <ItemsControl> 
        <ItemsControl.ItemTemplate> 
         <DataTemplate> 
          <Grid> 
           <!-- Anything in this item template works. The popup does not close --> 
          </Grid> 
         </DataTemplate> 
        </ItemsControl.ItemTemplate> 
       </ItemsControl> 
      </Grid> 
      </Border> 
     </Grid> 
    </Popup> 
</Grid> 

任何想法?谢谢。


编辑:解决

原来这是发生,因为它是这是从ListBox派生的自定义控制内。在我提出这个问题的时候,这似乎并不重要,对不起。

回答

0

原来这是发生,因为它是这是从Control派生的自定义控制内。在我提出这个问题的时候,这似乎并不重要,对不起。

0

我觉得你的情况的问题是位置或弹出窗口的大小。在尝试你的代码时,它确实有效,但是我必须在弹出窗口上设置Placement="Center"并在弹出窗口中设置网格的大小。

没有前者,弹出没有放在里面,而没有后者弹出窗口的大小只是它的内容(指没有外界点击)。

先尝试设置弹出窗口的背景,红色或东西,看看弹出实际上是正确地定位和尺寸。

+0

感谢您的建议。然而,这不是正确的,你不可能帮助不幸。经过几个小时的调试后,结果是因为它在一个自定义控件的'DataTemplate'中。这个控件是从'ListBox'派生出来的,并且导致了奇怪的行为。我修改了它,它按预期工作。 – erodewald 2013-04-29 15:50:55

+1

我很高兴你的上帝,它仍然工作 – 2013-04-29 16:26:01