[WPF] ComboBox Bug?

위 글과 비슷한 맥락의 정보공유입니다.

WPF는 버그가 꽤 많네요…

ComboBox에 Item을 추가하고 삭제하는 과정에서

System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘RelativeSource FindAncestor, AncestorType=‘System.Windows.Controls.ItemsControl’, AncestorLevel=‘1’’. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is ‘ComboBoxItem’ (Name=‘’); target property is ‘HorizontalContentAlignment’ (type ‘HorizontalAlignment’)
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’)

위 2개의 에러가 Item 마다 반복됩니다.

해결책은 아래 링크와 같습니다.

<Style TargetType="ComboBoxItem">
    <Setter Property="HorizontalContentAlignment" Value="Left" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
</Style>

위 코드를 App.xaml에 추가하면 됩니다.

혹시 비슷한 시리즈가 생기면 아래 댓글로 남기겠습니다.

5개의 좋아요

Binding Warning의 경우 프로그램이 죽는 것은 아니기 때문에 관심있게 보지 않는 한 모르고 넘어가는 경우가 많습니다.
다행인지 불행인지는 모르겠지만 어서 이런 버그들이 해결되었으면 하네요

3개의 좋아요