❔ How to set relative properties ?

TTotechsStrypper11/21/2022
SelectedCallingCode.CallingCode: +31
PhoneNumber: 123456
FullPhoneNumber: +31 123456
Are these syntaxsyntaxes correct on the FullPhoneNumber ?
Image
PPobiega11/21/2022
not really, no. You are declaring it a normal getter and setter, but its actually a "calculated" property that only uses other props to get its value
PPobiega11/21/2022
the setter doesnt use value, as you can see
PPobiega11/21/2022
You'll need to raise PropertyChanged events for FullPhoneNumber in the other setters
PPobiega11/21/2022
but have it declared simply as public string FullPhoneNumber => $"{SelectedCallingCode?.CallingCode} {PhoneNumber}";
TTotechsStrypper11/21/2022
Can you make this with a + in it ?
TTotechsStrypper11/21/2022
"+"
PPobiega11/21/2022
ofc
PPobiega11/21/2022
just add the +
TTotechsStrypper11/21/2022
okay
TTotechsStrypper11/21/2022
oh shoot I forgot
TTotechsStrypper11/21/2022
these are really from my boss
TTotechsStrypper11/21/2022
These props suppose to have inotifyprop change
PPobiega11/21/2022
Im assuming thats what SetProperty does
PPobiega11/21/2022
its a very common way to implement it
TTotechsStrypper11/21/2022
Do you think SetProp related to that
TTotechsStrypper11/21/2022
yeah
TTotechsStrypper11/21/2022
I think too
PPobiega11/21/2022
but you need to raise two events here
PPobiega11/21/2022
because when PhoneNumber changes, FullPhoneNumber also changes
PPobiega11/21/2022
same for calling code
PPobiega11/21/2022
I know the MVVM toolkit source generators support this, but in this case you might need to manually implement it
TTotechsStrypper11/21/2022
the dude ban me from using
TTotechsStrypper11/21/2022
it
TTotechsStrypper11/21/2022
because he want these crap to able to work with blazor
PPobiega11/21/2022
¯\_(ツ)_/¯
MMODiX11/21/2022
TTotechsStrypper11/21/2022
I tried this method but the prop require raise change for UI to work
PPobiega11/21/2022
Which is why I told you to raise events for that prop in the other props setters
PPobiega11/21/2022
since changing either of them will also change that value
TTotechsStrypper11/21/2022
Ah
TTotechsStrypper11/21/2022
I get it
PPobiega11/21/2022
public string CallingCode
{
    get => _callingCode;
    set
    {
        SetField(ref _callingCode, value);
        OnPropertyChanged(nameof(FullPhoneNumber));
    }
}

public string PhoneNumber
{
    get => _phoneNumber;
    set
    {
        SetField(ref _phoneNumber, value);
        OnPropertyChanged(nameof(FullPhoneNumber));
    }
}

public string FullPhoneNumber => $"+{CallingCode} {PhoneNumber}";
TTotechsStrypper11/21/2022
Thanks mate
AAccord11/22/2022
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.