2017-04-21 17 views
0

我打開我的組合框一旦獲得通過combobox.isDropDownOpen 我在控制檯ComboBoxItem綁定錯誤上打開組合框(WPF)

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')

及彼以下綁定錯誤重點是代碼:

private void combo_GotFocus(object sender, RoutedEventArgs e) 
{ 
    placeholder.Visibility = Visibility.Collapsed; 

    combo.IsDropDownOpen = true; 
} 

private void combo_LostFocus(object sender, RoutedEventArgs e) 
{ 
    if (combo.Text.Equals("")) 
    { 
     placeholder.Visibility = Visibility.Visible; 
    } 

} 

回答