Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF问题_Wpf_Xaml_Popup - Fatal编程技术网

WPF问题

WPF问题,wpf,xaml,popup,Wpf,Xaml,Popup,使用发现的概念请注意,ToggleButton.ishitestvisible绑定到Popup.IsOpen,并带有StaysOpen=“False”这意味着触摸弹出窗口之外的任何位置都会导致其关闭。然而 触摸/单击items控件中的ListBoxItem不会按预期关闭弹出窗口。触摸弹出窗口中的任何其他位置都会将其关闭。根据设置方式,这似乎不符合要求 <Grid ClipToBounds="True"> <Border Name="Root"> &

使用发现的概念请注意,
ToggleButton.ishitestvisible
绑定到
Popup.IsOpen
,并带有
StaysOpen=“False”
这意味着触摸
弹出窗口
之外的任何位置都会导致其关闭。然而

触摸/单击
items控件中的
ListBoxItem
不会按预期关闭
弹出窗口。触摸
弹出窗口中的任何其他位置都会将其关闭。根据设置方式,这似乎不符合要求

<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
派生的。对不起,在我提出这个问题的时候,它似乎不相关

我认为您的问题在于弹出窗口的位置或大小。当尝试你的代码时,它确实工作了,但是我必须在弹出窗口上设置
Placement=“Center”
,并在弹出窗口内设置网格的大小

如果没有前者,弹出窗口就不会放在内部,而如果没有后者,弹出窗口的大小只是其内容的大小(这意味着没有外部可点击)


首先尝试将弹出窗口的背景设置为红色或其他颜色,以查看弹出窗口的实际位置和大小是否正确。

结果表明,这是因为它位于从ListBox派生的自定义控件中。在我提出这个问题时,它似乎不相关,对不起。

谢谢你的建议。然而,这不是正确的一个,你不可能帮助不幸。经过几个小时的调试,结果证明这是因为它位于自定义控件的
DataTemplate
中。此控件派生自
ListBox
,导致出现奇怪的行为。我修改了它,它的工作原理与预期一致。