打开组合框(wpf)

时间:2017-04-21 12:21:49

标签: c# wpf data-binding combobox

一旦使用combobox.isDropDownOpen获得焦点,我就会打开我的组合框 我在控制台中收到以下绑定错误

  

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

}

1 个答案:

答案 0 :(得分:1)

这种绑定错误是无害的。有关更多信息,请参阅以下链接。

解决WPF中无害的绑定错误: https://weblogs.asp.net/akjoshi/resolving-un-harmful-binding-errors-in-wpf