我在usercontrol
一個SplitButton
,則usercontrol
的DataContext的是view
定義命令我希望splitbutton
結合。綁定命令不工作
正如我簡短的XAML代碼顯示如下,第一綁定工作,但第二(在DropDownContent
button
)不與輸出:
無法爲參照結合找到源「的RelativeSource FindAncestor ,AncestorType ='System.Windows.Controls.UserControl ....
或(如果我頂替結合使用的ReleativeSource
ElementName
代替表達)
無法爲參照 '的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>