2011-01-13 40 views
7

Tôi có cửa sổ đơn giản. Đây là những gì xảy ra khi tôi nhấp vào ComboBox: Screenshot Danh sách xuất hiện ở góc trên bên trái của màn hình thay vì bên dưới Hộp tổ hợp.C# Hành vi combobox WPF lạ

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> 
+0

Nó có thể liên quan đến điều này: http://stackoverflow.com/questions/1998024/wpf-combobox-dropdown-part-appears-in-the-wrong-place – MarcelDevG

+2

Làm việc ok cho tôi. Những gì bạn có trong mã phía sau? –

+0

@Andrei Pana Điều đó xảy ra khi tôi mở cửa sổ này trong Sự kiện được tải từ một sự kiện khác. Tôi thực sự cần sửa chữa cho điều đó. – Hooch

Trả lời

5

Thay vì mở nó trực tiếp trong trường hợp Loaded, chỉ xếp hàng nhắn khác trên Dispatcher để mở nó.

+0

+1 Kent Boogaart. – user7116

+0

Ya, nó hoạt động. –

1

Tôi đã thực hiện chính xác điều này và chỉ đăng một ví dụ tại số WPF ComboBox DropDown part appears in the wrong place làm việc cho tôi. Người đọc quan tâm có thể đến đó để kiểm tra nội dung bình luận của tôi, nhưng đây là đoạn (Chú ý: WindoBaseLoadedHandler là "Loaded =" xử lý theo quy định tại các XAML):

protected void WindowBaseLoadedHandler(object sender, RoutedEventArgs e) 
{ 

... dòng không cần thiết của mã gỡ bỏ. ..

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; 
     })); 
    }