Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to hide an object via the properties of another object I do not know what the problem is, but it does not work

Binding code
XML
<StackPanel Orientation="Horizontal">
    <Grid Margin="25,0,0,0" HorizontalAlignment="Center">
        <TextBlock
            Text="اسم المستخدم" 
            FontWeight="Light"
            FontSize="18"
            Foreground="White"
            Background="Transparent"
            Width="230"
            Opacity="0.5"
            Height="28"
            Visibility="{Binding Path=VisbTbU , Mode=TwoWay}"/>
        <TextBox 
            FontFamily="Helvetica"
            FontWeight="Light"
            FontSize="18"
            HorizontalAlignment="Center"
            Foreground="White"
            Background="Transparent"
            BorderThickness="0"
            Width="235"
            HorizontalContentAlignment="Left"
            Opacity="0.5"
            Height="25"
            Text="{Binding UserLog}"
        />
    </Grid>
    <iconPacks:PackIconMaterial 
        Kind="Account"
        VerticalAlignment="Center"
        HorizontalAlignment="Center"
        Foreground="White"
    />
</StackPanel>

viewmodel code
C#
public VmWinLogin()
{
    VisbTbp = Visibility.Visible;
    VisbTbp = Visibility.Visible;
    UserLog = "";
    UserPass = "";
}

private Visibility _VisbTbU ;

public Visibility VisbTbU
{
    get => _VisbTbU;
    set
    {
        _VisbTbU = value;
       // OnPropertyChanging();
       OnPropertyChanging();
    }
}


private string _UserLog ;

public string UserLog
{
    get => _UserLog .Trim();
    set
    {
        _UserLog = value .Trim();
        OnPropertyChanging();
        if (_UserLog == "")
        {
            VisbTbU = Visibility.Visible;
        }
        else
        {
            VisbTbU = Visibility.Hidden;
        }
    }
}

basemodel code
C#
public event PropertyChangingEventHandler PropertyChanging;

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanging([CallerMemberName] string propertyName = null)
{
    PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
}


What I have tried:

I tried to follow the implementation to make sure the value of the property did not change and I found that it changed, but there is no effect on the object.
Posted
Updated 22-May-20 0:29am
v2

1 solution

Technically, OnPropertyChanging can be eventually called before corresponding property is modified. Once the property has been modified, then OnPropertyChanged has to be called. You are only calling OnPropertyChanging after the modification, so there is a great chance that the system never catches the PropertyChanged event.
 
Share this answer
 
Comments
khaled_basher 22-May-20 10:47am    
nvoke PropertyChanged It also did not work

public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { VerifyPropertyName(propertyName); PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(propertyName)); }
phil.o 22-May-20 11:06am    
Did you really change the code in the VisbTbU setter as well?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900