Entry value updated in VM but not in UI - Xamarin Forms

Ika777Ika777 Member ✭✭

In my VM I am assigning value to CurrentItem.SecondValue when Toggle is checked it gets whatever value is entered in FirstValue Entry, but value is not getting updated in UI unless I refresh it/navigate between pages. When I debug it I see that CurrentItem.SecondValue is updated in VM. Any suggestions how it can be fixed?
XAML:

<renderer:CustomKeyEntry x:Name="FirstValue" Text="{Binding CurrentItem.FirstValue}" HeightRequest="40" WidthRequest="250" BackgroundColor="#FFFFFF"  Margin="15, 0" TextColor="Black" IsEnabled="{Binding IsThisEnabled}" ReturnType="Next" />  

<common:Toggle Text="{i18n:Translate Use_This_Number}" Checked="{Binding SecondValueIsFirstValue}" TextColor="Gray" HorizontalOptions="EndAndExpand" IsEnabled="{Binding IsThisEnabled}" Margin="0,0,10,0" />  

<renderer:CustomKeyEntry x:Name="SecondValue" Text="{Binding CurrentItem.SecondValue}" HeightRequest="40" WidthRequest="250" BackgroundColor="#FFFFFF"  Margin="15, 0" TextColor="Black" ReturnType="Next"/> 

ViewModel:

private Boolean _secondValueIsFirstValue= false;

    public Boolean SecondValueIsFirstValue
    {
        get { return _secondValueIsFirstValue; }
        set
        {                
            if (_secondValueIsFirstValue!= value)
            {
                if (value)
                {
                    CurrentItem.SecondValue = CurrentItem.FirstValue;
                    OnPropertyChanged();
                }                       
              SetProperty(ref _secondValueIsFirstValue, value);                                     
            }               
        }
    }

private ItemDTO _currentItem;
public ItemDTO CurrentItem
        {
            get { return _currentItem;}
            set { SetProperty(ref _currentItem, value); }
        }

 //DTO Class
 public class ItemDTO : INotifyPropertyChanged    
    {
        public event PropertyChangedEventHandler PropertyChanged;                     
        ....
    }

Best Answer

  • Ika777Ika777 ✭✭
    Accepted Answer

    Updating Fody NuGet package fixed the issue.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Try it as a BindableProperty instead of a plain old CLR property.

  • LandLuLandLu Member, Xamarin Team Xamurai

    @Ika777 When your FirstValue changes, it triggers the CurrentItem.FirstValue's set method. But you placed your CurrentItem.SecondValue's set method in the SecondValueIsFirstValue set method, it won't fire this set behavior. So your UI won't change.
    Maybe, when you return back to the page, the SecondValueIsFirstValue's set method triggers so that your CurrentItem.SecondValue's value changes.

  • Ika777Ika777 Member ✭✭

    @ClintStLaurent Will try, thank you.

  • Ika777Ika777 Member ✭✭
    Accepted Answer

    Updating Fody NuGet package fixed the issue.

Sign In or Register to comment.