위 글과 비슷한 맥락의 정보공유입니다.
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에 추가하면 됩니다.
혹시 비슷한 시리즈가 생기면 아래 댓글로 남기겠습니다.