C# 奇怪的 WPF 组合框行为

标签 c# .net wpf xaml combobox

我有一个简单的窗口。 这是当我单击 ComboBox 时发生的情况: Screenshot 列表显示在屏幕的左上角,而不是组合框下方。

XAML:

<Window x:Class="WpfPortOfTestingCamera.VideoSettings"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Video Settings" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" ShowInTaskbar="False" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" SizeToContent="WidthAndHeight" d:DesignHeight="167">
    <StackPanel Name="stackPanel1" VerticalAlignment="Top" HorizontalAlignment="Center">
        <GroupBox Header="Settings" Name="groupBox1">
            <Grid Name="grid1" VerticalAlignment="Center" HorizontalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80*" />
                    <ColumnDefinition Width="175*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Label Content="Resolution:" Height="28" Name="label1" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Center" />
                <Label Content="Framerate:" Height="28" HorizontalAlignment="Left" Margin="0" Name="label2" VerticalAlignment="Center" Grid.Row="1" />
                <ComboBox Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="0" Name="comboBox1" VerticalAlignment="Center" Width="150" SelectionChanged="comboBox1_SelectionChanged" />
                <ComboBox Height="23" HorizontalAlignment="Left" Margin="0" Name="comboBox2" VerticalAlignment="Center" Width="150" Grid.Column="1" Grid.Row="1" SelectionChanged="comboBox2_SelectionChanged" />
            </Grid>
        </GroupBox>
        <Label Name="labelSelectedSize" Content="Size @ FPS" />
        <Button Name="button1" Content="Apply" Click="button1_Click" />
    </StackPanel>
</Window>

最佳答案

无需在 Loaded 事件中直接打开它,只需在 Dispatcher 上排队另一条消息即可打开它。

关于C# 奇怪的 WPF 组合框行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4677701/

相关文章:

c# - 在客户端中止时取消 WCF 操作

c# - Chilkat C# Crypt2 与 .NET 框架加密

c# - 如何判断类型是否为 "simple"类型?即持有一个单一的值(value)

c# - 用户创建的像素字节数组似乎无法正确更新(WPF)

c# - 即使声明中存在角色,IsInRole 也会返回 false

WPF:在 DataGridComboBoxColumn 中显示验证工具提示

.net - 具有扎实的 WPF/.NET 背景学习 ASP.NET MVC

WPF ListView 如果高度设置为自动则没有滚动条

c# - 将 PDF 转换为图像 - 库或命令行 - 免费

c# - 每个枚举数组都实现了 IEnumerable<EveryOtherEnum>。我该如何解决这个问题?