Click here to Skip to main content
15,897,226 members

Wpf netframeworkcore 3.1 MVVM visibility

khaled_basher asked:

Open original thread
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.
Tags: .NET Core, WPF, MVVM

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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