Click here to Skip to main content
14,608,021 members
Rate this:
Please Sign up or sign in to vote.
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
<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
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
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Comments
khaled_0b 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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100