Need to change button visibility based on database query. I tried below and it doesn't do what I've expected. AlarmEnableStatus
does change the value as expected but UI does not change.
HomeView.xaml
<Button x:Name="AlarmButton" Content="Warning!"
Margin="12,0,6,0" BorderThickness="1" Width="100" Height="30"
Style="{StaticResource AlarmButtonStyle}"
Foreground="#717171" FontWeight="SemiBold" FontSize="17"/>
-------
<Style x:Key="AlarmButtonStyle" TargetType="Button" BasedOn="{StaticResource CornerRadiusButtonStyle}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding AlarmEnableStatus}" Value="False">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
HomeViewModel.cs
public bool AlarmEnableStatus { get; private set; }
-------
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(60);
timer.Tick += timer_Tick;
timer.Start();
-------
private void timer_Tick(object sender, EventArgs e)
{
int isCount = HeaderDataSet.PendingFailedCount;
if ((!AlarmEnableStatus) & (isCount > 0))
{
AlarmEnableStatus = true;
}
else
{
AlarmEnableStatus = false;
}
}