2012-07-12 2 views
0

이상한 문제가 있습니다. 각 스택에 두 개의 스택 패널이 있으며 각 스택에 두 개의 스택 패널의 데이터 컨텍스트가 동일하며 버튼의 IsEnabled 속성도 같은 속성으로 설정되어 있습니다. 그러나 하나 개의 버튼이 비활성화이고 다른 하나는 사용할 수 있습니다 :이상한 실버 라이트 바인딩 문제

StackPanel의 # 1 (활성화) :

<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Height="23" DataContext="{Binding ElementName=LayoutRoot, Path=DataContext}"> 
    <TextBox Grid.Row="0" Grid.Column="1" Height="23" Width="220" Name="txtBarcode"></TextBox> 
    <Button IsEnabled="{Binding CanAdd}" cal:Click.Command="{Binding AddBarcodeCommand}" Width="40" Content=". . ." Margin="5,0"></Button> 
</StackPanel> 

StackPanel에 # 2 (장애인) : 어떤 데이터 바인딩 오류를 보지 못했다

<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" DataContext="{Binding ElementName=LayoutRoot, Path=DataContext}" > 
    <Button HorizontalAlignment="Right" cal:Click.Command="{Binding ElementName=LayoutRoot, Path=DataContext.SaveCommand}" Grid.Row="3" Grid.Column="1" Height="30" Content="Create Batch" Width="130"></Button> 
    <Button IsEnabled="{Binding CanAdd}" Height="30" Content="Apply" Width="130" HorizontalAlignment="Right" Margin="5,0"></Button> 
</StackPanel> 

출력 창에. 제가 누락 된 것이 있습니까?

답변

2

이 때문에 첫 번째 단추에 명령의 아마이 명령에 그것을 위해 정의 된 CanExecute 메서드가

cal:Click.Command="{Binding AddBarcodeCommand} 

경우 그 메소드가 false를 반환 할 때,이 버튼이 비활성화됩니다.

그것은 또한 내가 바인딩 IsEnabled을 제거 할 SaveCommand

에 적용하고 명령의 포인트가 그렇게 할의로 CanExecute이 일을 할 수 있도록,
을 수 있지만, 할 수도 있습니다 수정 CanExecute 로직 또는 이를 제거하고 IsEnabled 바인딩이 작동하도록하십시오.