2009-10-01 5 views
-1

3 개의 단추가있는 UserControl이 있는데, 편집 및 삭제 추가. 아무것도 미쳤어.WPF Button의 UserControl : UserControl을 구현하는 방법?

내 부모 UserControl에서 내 단추 UserControl을 삽입합니다. 그들은 예상대로 나타납니다. 하지만 내 부모 UserControl에서 각 단추에 명령을 바인딩하고 싶습니다. 상위 UserControl에서 각 단추의 매개 변수에 어떻게 액세스합니까? UserControl 다음 이러한 속성에 바인딩 할 수 있습니다에

public class UserControl 
{ 
    public ICommand AddCommand 
    { 
     ... 
    } 

    ... 
} 

XAML :

답변

3

이 작업을 수행하는 가장 깨끗한 방법은 당신이 UserControl를 호스팅하는 컨트롤에서 조작 할 당신의 UserControl에 종속성 속성을 노출하는 것입니다

<UserControl> 
    <Button Command="{Binding AddCommand}">Add</Button> 
    ... 
</UserControl> 

그리고, 물론, 호스트 후 사용할 수 이러한 속성 :

<Window> 
    <local:YourUserControl AddCommand="{Binding MyAddCommand}"/> 
</Window>