Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button Visibility Binding doesn't update

I have a button on my Xaml page that its visibility is binded to a variable of Type : SYSTEM.Windows.Visibility in the view model, for the first time the page is loaded whether I set the variable to Hidden or Visible , it works fine. but aftre doing some operation when I change the variable to other status my GUI doesn't update.

Here are my xaml and MVVM

<Button Content="Extend" Name="btnExtend" Command="{Binding ExtendCommand}" Visibility="{Binding isVisible}"  Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right" Width="80" Margin="0,0,100,0" Height="25"/>

and view model :

Public Property isVisible As System.Windows.Visibility

Public Sub New()
        isVisible = System.Windows.Visibility.Visible
End Sub

Public Sub diable()
        isVisible = System.Windows.Visibility.Visible
End Sub

I read in some topics to change the variable to Boolean and use a BooleanToVisibilityConverter , I tried this too, but the result was the same.

I really don't get it what I do wrong.

like image 939
Maryam Arshi Avatar asked Jan 12 '23 01:01

Maryam Arshi


1 Answers

your xaml code should be

<Button Content="Extend" Name="btnExtend" Command="{Binding ExtendCommand}" Visibility="{Binding isVisible,Mode=Twoway}"  Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right" Width="80" Margin="0,0,100,0" Height="25"/>

and your Viewmodel Code Should be

  private Visibility _isVisible ;

public Visibility isVisible 
{
    get { return _isVisible ;}
    set { _isVisible  = value;RaisePropertyChanged("isVisible ");}
}
like image 150
Dhaval Patel Avatar answered Jan 17 '23 21:01

Dhaval Patel