-6ren">
gpt4 book ai didi

c# - ComboBox 下拉菜单出现在窗口下方

转载 作者:行者123 更新时间:2023-11-30 22:27:31 25 4
gpt4 key购买 nike

所以我有一个如下所示的组合框,编码如下;

AllowsTransparency="True" Background="Transparent">
<Border CornerRadius="10" Background="Beige" BorderBrush="Aqua" BorderThickness="2">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Label Name="lblText"></Label>
<ComboBox Name="cbxNumbers"></ComboBox>
<TextBox Name="txtNumbers" Visibility="Collapsed"></TextBox>
<Button HorizontalAlignment="Center" Name="btnDone"
Click="btnDone_Click">That's Right!</Button>
</StackPanel>
<Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="1"
FontSize="8" Name="btnChangeInput" Click="btnChangeInput_Click">Let me chose the number
</Button>
</Grid>
</Border>

然后像这样填充代码;

lblText.Content = Text;
cbxNumbers.Items.Add(5);
cbxNumbers.Items.Add(10);
cbxNumbers.Items.Add(50);
cbxNumbers.Items.Add(100);
cbxNumbers.Items.Add(1000);
cbxNumbers.Items.Add(10000);
cbxNumbers.Items.Add(100000);
cbxNumbers.Items.Add(1000000);
cbxNumbers.SelectedIndex = 0;

我的问题很明显,为什么我的 Dropdown 显示在我的窗口下方?

ComboBoxProblem

更新

引用微软

Thank you for reporting this issue. Though this issue is under investigation, we will likely not have a fix available in .NET 4.0. We will update this bug again when we are able to fix the issue in a future release. Thanks!

太好了...有什么变通的想法吗?

最佳答案

这是一个带有 AllowTransparency=TRUE 的有据可查的错误。它只发生在某些运行 Win XP 的计算机上。

http://connect.microsoft.com/VisualStudio/feedback/details/465964/wpf-combobox-dropdown-list-appears-behind-the-form-when-allowstransparency-true

找到解决方法 here :

As noted before, this is an issue with layered windows on XP. There is not much that can be done at the WPF level to solve this, and given that XP is no longer being serviced this isn't very likely to be fixed. There are potentially workarounds you can employ, though.

The source of the problem is that WPF uses something called "Layered Windows" when WindowStyle=None and AllowsTransparency=True. Often the reason for doing this is to implement custom window chrome. Recently the WPF team published a library that allows you to get custom chrome without resorting to layered windows. The library is available at

http://code.msdn.microsoft.com/WPFShell

This doesn't support per-pixel opacity, but it does allow for completely custom rendering of the window, including areas normally managed by the system. It lets you set the radii of the windows corners, but not have a completely arbitrary shape. If you can use this library instead of AllowsTransparency=True then it should solve this issue.

Microsoft 已发布 hotfix , 但它似乎并没有解决与该问题相关的所有问题。

关于c# - ComboBox 下拉菜单出现在窗口下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11248164/

25 4 0