I have a SplitButton
in my usercontrol
, the usercontrol
's datacontext is a view
which defines command I want the splitbutton
binding to.
As my brief xaml code showing below, the first binding works, but the second (button
in the DropDownContent
) doesn't with the output:
Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl....
or (if I replace binding expression using ElementName
instead of ReleativeSource
)
Cannot find source for binding with reference 'ElementName=uc'...
<UserControl x:Name="uc"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
>
<Grid>
<ItemsControl ItemsSource="{Binding ItemList, IsAsync=True}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<extToolkit:SplitButton Command="{Binding
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
Path=DataContext.OpenCommand,
Mode=OneWay}"
CommandParameter="{Binding}"
Content="{Binding ID}">
<extToolkit:SplitButton.DropDownContent>
<Button Command="{Binding
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},
Path=DataContext.OpenCommand,
Mode=OneWay}"
CommandParameter="{Binding}"
Content="{Binding ID}"/>
</extToolkit:SplitButton.DropDownContent>
</extToolkit:SplitButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>