-1
我有一個UserControl,它有3個按鈕,添加編輯和刪除。沒有什麼瘋狂的。WPF UserControl的按鈕:如何實現UserControl?
在我的父級UserControl上,我插入了我的按鈕UserControl。它們按預期顯示。但我想要將命令綁定到我的Parent UserControl中的每個按鈕。如何從父UserControl訪問每個按鈕的參數?
我有一個UserControl,它有3個按鈕,添加編輯和刪除。沒有什麼瘋狂的。WPF UserControl的按鈕:如何實現UserControl?
在我的父級UserControl上,我插入了我的按鈕UserControl。它們按預期顯示。但我想要將命令綁定到我的Parent UserControl中的每個按鈕。如何從父UserControl訪問每個按鈕的參數?
做到這一點,最徹底的方法是在你的UserControl
暴露依賴屬性,你希望從控制託管UserControl
操作:
public class UserControl
{
public ICommand AddCommand
{
...
}
...
}
的XAML在UserControl
然後可以綁定到這些屬性:
<UserControl>
<Button Command="{Binding AddCommand}">Add</Button>
...
</UserControl>
,當然,您的主機可以再使用這些屬性:
<Window>
<local:YourUserControl AddCommand="{Binding MyAddCommand}"/>
</Window>