繁体   English   中英

C#奇怪的WPF组合框行为

[英]C# Strange WPF Combobox Behavior

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

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上排队另一个消息以将其打开。

我碰到了这个问题,只是在WPF ComboBox上发布了一个示例, DropDown部分出现在对我有用的错误位置 有兴趣的读者可以去那里阅读我的评论,但这是代码段(注意:WindoBaseLoadedHandler是XAML中指定的“ Loaded =“处理程序):

protected void WindowBaseLoadedHandler(object sender, RoutedEventArgs e)
{

...删除了不必要的代码行...

    if (DataContext != null)
    {
        Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
        {
            this.IsEnabled = false;

            LoginDlg loginDlg = new LoginDlg();
            loginDlg.ShowDialog();

            if (!loginDlg.Success)
            {
                /*-----------------------------------
                 * Log on failed -- terminate app...
                 *----------------------------------*/
                ...termination logic removed...
            }

            this.IsEnabled = true;
        }));
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM