2010-02-24 8 views
2

을 클릭 바인딩 할 수 없습니다 . 이것은 명령 작업을하기위한 테스트 응용 프로그램입니다.왜 내 실버 버튼이 난 그냥 버튼 내가 뷰 모델에 만든 간단한 명령을 클릭 결합하기 위해 노력하고있어 실버 라이트 3 프리즘 간단한 테스트 응용 프로그램을 가지고 프리즘 DelegateCommand

System.Windows.Data Error: BindingExpression path error: 'MyCommand' property not found on 'Bind1.ShellViewModel' 'Bind1.ShellViewModel' (HashCode=8628710). BindingExpression: Path='MyCommand' DataItem='Bind1.ShellViewModel' (HashCode=8628710); target element is 'System.Windows.Controls.Button' (Name=''); target property is 'Command' (type 'System.Windows.Input.ICommand')..

가 여기 내 쉘 뷰의 :

<UserControl 
x:Class="Bind1.ShellView" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:Commands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation" 
Width="400" Height="300"> 
<Grid x:Name="LayoutRoot" Background="White"> 
    <StackPanel> 
     <TextBlock Text="Hello World!"></TextBlock> 
     <Button Content="{Binding ButtonLabel}" Commands:Click.Command="{Binding Path=MyCommand}" /> 
    </StackPanel> 
</Grid> 
</UserControl> 

뷰의 생성자에서 (내가 ViewModel을 인스턴스화 내가 그것을 실행하면 나는보기가 명령을 찾을 수 있다고 말해 바인딩 오류 나는) ... 아직 용기를 사용하는 방법에 대한 걱정 안 해요 :

: 여기
public partial class ShellView : UserControl 
{ 
    public ShellView() 
    { 
     InitializeComponent(); 
     DataContext = new ShellViewModel(); 
    } 
} 

내 뷰 모델입니다
public class ShellViewModel 
{ 
    public string ButtonLabel { get { return "DoIt!!"; } } 
    public DelegateCommand<object> MyCommand = new DelegateCommand<object>(ExecuteMyCommand); 
    public static void ExecuteMyCommand(object obj) 
    { 
     Debug.WriteLine("Doit executed"); 
    } 
} 

단추 레이블 바인딩이 제대로 작동하여보기에서 ViewModel OK를 찾을 수 있습니다.

왜 MyCommand를 찾을 수 없습니까? 나에게 화를 운전하는 것 - 나는 분명히 매우 잘못된 간단한 일을하고 ...

덕분에 많이.

답변

2

바보 같은 ... 시간을 낭비하게해서 죄송합니다.

MyCommand 속성을 잊어 버렸습니다! 너무 많이 화면을 쳐다 보지. 너무 바인딩 인프라를 볼 수 없었다 단지 공공 분야였다. 모두 잘되었습니다.