2013-11-21 64 views
0

這看起來應該很容易找到/實現,但我沒有運氣。ComboboxItem Expanding

我需要一個簡單的組合框,其中的一個項目向右擴展時,鼠標懸停在它的更多選項。我嘗試添加第二個組合框作爲第一個組合框的孩子,但我無法使用它開放到正確的位置。

我沒有結婚的孩子combobox,會採取任何好的建議。

的代碼下面給我一個錯誤:「拋出一個異常‘’設置屬性」 System.Windows.Controls.ItemsControl.ItemsSource行號「154」和線位置「123」,其中,管線154是

<ComboBoxItem Tag="163" Style="{StaticResource blackComboBoxItem}">£ - Pound</ComboBoxItem> 

這是代碼:

<ComboBox Name="SettingsCmbx" Foreground="White" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" SelectedIndex="0" Width="80" Style="{StaticResource blackGradientComboBox}" Margin="3"> 
    <ComboBox.ItemsSource> 
     <CompositeCollection> 
      <ComboBoxItem Name="Options" IsEnabled="False" Style="{StaticResource blackComboBoxItem}" FontSize="12" Foreground="White">Options</ComboBoxItem> 
      <ComboBoxItem Style="{StaticResource blackComboBoxItem}">Guidelines</ComboBoxItem> 
      <ComboBoxItem Style="{StaticResource blackComboBoxItem}">Copy Investigation</ComboBoxItem> 
      <ComboBox Name="CurrencySelectCmbx" Foreground="White" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" SelectedIndex="0" Width="80" Style="{StaticResource blackGradientComboBox}"> 
       <Popup x:Name="PART_Popup" Placement="Right"></Popup> 
       <ComboBox.ItemsSource> 
        <CompositeCollection> 
         <ComboBoxItem Tag="36" Style="{StaticResource blackComboBoxItem}">Currency</ComboBoxItem> 
         <ComboBoxItem Tag="36" Style="{StaticResource blackComboBoxItem}">$ - Dollar</ComboBoxItem> 
         <ComboBoxItem Tag="163" Style="{StaticResource blackComboBoxItem}">£ - Pound</ComboBoxItem> 
        </CompositeCollection> 
       </ComboBox.ItemsSource> 
      </ComboBox> 

爲了給出的後端是如何實現的(不完全的)一個想法:

Private Sub SettingsCmbx_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles SettingsCmbx.SelectionChanged 
    Dim selection As String = SettingsCmbx.SelectedItem.content.ToString() 
    If selection = "Options" Then Return 

    If selection = "Guidelines" Then 
     Dim answer As MsgBoxResult = MsgBox("Navigate to NDIA website to view 32 Guidelines?", MsgBoxStyle.OkCancel) 
     If answer = MsgBoxResult.Ok Then 
      Process.Start("http://www.ndia.org/Divisions/Divisions/Procurement/PMSC/Pages/PMSCCommitteeDocuments.aspx") 
     End If 
    ElseIf selection = "About" Then 
     Dim helpwindow As New HelpWindow 
     helpwindow.Show() 
    ElseIf selection = "Copy Investigation" Then 
     Dim _investigationcopymappingwindow As New InvestigationCopyMappingWindow 
     _investigationcopymappingwindow.Show() 
    ElseIf selection = "Currency" Then 
     'WHERE THE CHILD SELECTION CODE SHOULD THEORETICALLY GO 
    End If 

    SettingsCmbx.SelectedIndex() = 0 
End Sub 
+0

我將尋找一個菜單項,在具有ComboBox。 –

回答

1

您可以使用菜單系統組合框裏面:

  <ComboBox Grid.Column="2" Height="25"> 
       <MenuItem x:Name="MenuItem1" Header="Testing" Background="White" BorderThickness="0" MouseEnter="MenuItem_MouseEnter"> 
       <MenuItem Header="IfThisWorks" Background="White" BorderThickness="0"/> 
      </MenuItem> 

使用這個打開菜單時,鼠標懸停:

private void MenuItem_MouseEnter(object sender, MouseEventArgs e) 
    { 
     MenuItem1.IsSubmenuOpen = true; 
    } 
+0

這工作,但我不能爲我的生活得到menuitem填補組合框提供它的空間。左右兩側有兩個空白區域,看起來太小了。建議? – user