Reputation: 1327
I have a weird problem. I have two stack panels, with a button in each, the data context of both stack panels are the same and the IsEnabled property on the buttons are also set to the same property. Yet one button is disabled and the other is enabled:
StackPanel #1 (Enabled):
<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 (Disabled):
<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>
I did not see any databinding errors in the output window. Is there something that I am missing?
Upvotes: 0
Views: 84
Reputation: 16628
It's probably because of your command in the first Button:
cal:Click.Command="{Binding AddBarcodeCommand}
If that command has a CanExecute method defined for it, it will disable the button when that method returns false.
It may also apply to SaveCommand
I would remove the IsEnabled
binding and let the CanExecute
do its thing as it's the point of commands to do so,
but you can also fix the CanExecute logic or remove it and let the IsEnabled binding work.
Upvotes: 2