メモ:
WPFプロジェクトで、MahApps.Metro の DropDownButton使っていたら実行時エラーが出た。(動作は問題ない?)
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 'MenuItem' (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 'MenuItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
MahApps というよりWPF関連の既知の動作っぽい。
MenuItemを対象に Style設定をして回避。
<mah:DropDownButton> <mah:DropDownButton.ItemContainerStyle> <Style BasedOn="{StaticResource {x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="VerticalContentAlignment" Value="Center" /> </Style> </mah:DropDownButton.ItemContainerStyle> </mah:DropDownButton>
参考: