C#奇怪的WPF组合框行为 [英] C# Strange WPF Combobox Behavior
本文介绍了C#奇怪的WPF组合框行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有简单的窗口。 这是当我点击组合框会发生什么: 列表显示在屏幕的左上角,而不是根据组合框。
XAML:
<窗口x:类=WpfPortOfTestingCamera.VideoSettings
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
标题=视频设置WindowStartupLocation =CenterOwnerResizeMode =NoResizeShowInTaskbar =FALSEMC:可忽略=D的xmlns:D =http://schemas.microsoft.com/ex$p$pssion/blend / 2008的xmlns:MC =http://schemas.openxmlformats.org/markup-compatibility/2006SizeToContent =WidthAndHeightD:DesignHeight =167>
< StackPanel的名称=stackPanel1VerticalAlignment =热门的HorizontalAlignment =中心>
<分组框标题=设置名称=groupBox1>
<网名=GRID1VerticalAlignment =中心的HorizontalAlignment =中心>
< Grid.ColumnDefinitions>
< ColumnDefinition WIDTH =80 */>
< ColumnDefinition WIDTH =175 */>
< /Grid.ColumnDefinitions>
< Grid.RowDefinitions>
< RowDefinition />
< RowDefinition />
< /Grid.RowDefinitions>
<标签内容=分辨率:高度=28NAME =label1的保证金=0的HorizontalAlignment =左VerticalAlignment =中心/>
<标签内容=帧率:高度=28的HorizontalAlignment =左保证金=0NAME =标签2VerticalAlignment =中心Grid.Row =1/>
<组合框Grid.Column =1高度=23的HorizontalAlignment =左保证金=0NAME =ComboBox1的VerticalAlignment =中心WIDTH =150的SelectionChanged =comboBox1_SelectionChanged/>
<组合框高度=23的HorizontalAlignment =左保证金=0NAME =comboBox2VerticalAlignment =中心WIDTH =150Grid.Column =1Grid.Row =1的SelectionChanged = comboBox2_SelectionChanged/>
< /网格>
< /分组框中>
<标签名称=labelSelectedSizeCONTENT =大小@ FPS/>
<按钮名称=Button1的CONTENT =应用点击=的button1_Click/>
< / StackPanel的>
< /窗>
解决方案
而不是直接在Loaded事件打开它,只是排队的调度另一条消息以打开它。
I have simple window. This is what happens when I click ComboBox: List appears in upper left corner of screen instead of under 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>
解决方案
Instead of opening it directly in the Loaded event, just queue another message on the Dispatcher to open it.
这篇关于C#奇怪的WPF组合框行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文