0

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;
  }
}
  • Your AlarmEnableStatus property does not fire a change notification. Consider implementing the INotifyPropertyChanged interface and fire its PropertyChanged event from the property setter. – Clemens Feb 04 '20 at 11:33
  • Thanks @Clemens. Didn't know about the ```INotifyPropertyChanged ``` – ITSthe1 Feb 05 '20 at 12:02

0 Answers0