Reputation: 1736
I have a button where is enabled property should happen twice. In the viewmodel if the IsEnabled property is set to false the button should be disabled which works fine. On the other hand when the Validate button in the UI is disabled, this button should also be disabled that is not working which indicates that the Data Trigger is not working. Please help.
<Button x:Name="BtnValidate" Content="Validate" Height="24" VerticalAlignment="Top" Grid.Column="2" Width="83" Command="{Binding ValidateCommand}" IsEnabled="{Binding IsValidateEnabled}" HorizontalAlignment="Left" Margin="8,28,0,0" />
<Button Name="BtnReload" IsEnabled="{Binding IsEnabled}" HorizontalAlignment="Left" Width="123" Grid.Row="0" Grid.Column="5" Content="Reload" Command="{Binding DateCommand}" Margin="8,24,0,32">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=BtnValidate,Path=IsEnabled}" Value="False">
<Setter Property="IsEnabled" Value="False"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
Upvotes: 0
Views: 3470
Reputation: 132548
Properites set in the <Tag>
of the object take precendence over any property set in a <Style>
, so in your case the IsEnabled="{Binding IsEnabled}"
is always going to be used. See MSDN's Dependency Property Precedence List for more information.
The solution would be to move the IsEnabled
property out of the tag definition and into the style, since properties set in a Trigger take precedence over properties set in the <Style>
<Button Name="BtnReload" Content="Reload" Command="{Binding DateCommand}">
<Button.Style>
<Style TargetType="Button">
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=BtnValidate,Path=IsEnabled}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
Upvotes: 5