x:bind UI not update when PropertyChanged in UWPWhy is it important to override GetHashCode when Equals method is overridden?When to use struct?How do I update the GUI from another thread?How to get property name from the sender object of an INotifyPropertyChanged PropertyChanged eventDatabinding issue with stopwatched elapsedConnecting SQL Azure to Windows Phone 7 using WCFEntity Framework 5 Updating a RecordWPF Binding not updating from DispatcherTimerObservable.Interval not updating UI with expected frequencyUWP Xaml Textblock Data Binding - UI not updating even though the property is updated

Analog is Obtuse!

How hard is it to sell a home which is currently mortgaged?

Coefficients of the characteristic polynomial

can’t run a function against EXEC

When to apply Lorentz transformations and laws of time dilations and length contractions: explanations

Three column layout

“Faire” being used to mean “avoir l’air”?

Math PhD in US vs Master + PhD in Europe

How to start learning the piano again

What's the point of DHS warning passengers about Manila airport?

Was touching your nose a greeting in second millenium Mesopotamia?

Was "I have the farts, again" broadcast from the Moon to the whole world?

For people who believe in Jesus and not the devil, what happend in the desert?

Do I have to roll to maintain concentration if a target other than me who is affected by my concentration spell takes damage?

Why did this meteor appear cyan?

How to determine what is the correct level of detail when modelling?

Can you sign using a digital signature itself?

How was film developed in the late 1920s?

The difference between Rad1 and Rfd1

Should I hide continue button until tasks are completed?

Why won't the ground take my seed?

I played my first (rapid) tournament recently and I wanted to calculate my ELO

In native German words, is Q always followed by U, as in English?

Bash echo $-1 prints hb1. Why?



x:bind UI not update when PropertyChanged in UWP


Why is it important to override GetHashCode when Equals method is overridden?When to use struct?How do I update the GUI from another thread?How to get property name from the sender object of an INotifyPropertyChanged PropertyChanged eventDatabinding issue with stopwatched elapsedConnecting SQL Azure to Windows Phone 7 using WCFEntity Framework 5 Updating a RecordWPF Binding not updating from DispatcherTimerObservable.Interval not updating UI with expected frequencyUWP Xaml Textblock Data Binding - UI not updating even though the property is updated






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm using x:Bind and INotifyPropertyChanged to update UI in UWP application. But it behaves like OneTime binding even though I set it to OneWay.



Bindings.Update() works, but I want to know why INotifyPropertyChanged fails.



XAML



<TextBlock Text="x:Bind staffVM.Name, Mode=OneWay"/>


Code-behind:



private StaffViewModel staffVM;
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)

// I want to change staffVM according to ListView's selection.
staffVM = staffListView.SelectedItem as StaffViewModel;
staffVM.Update(); // If change this to Bindings.Update(), It works.



ViewModel:



public class StaffViewModel: INotifyPropertyChanged

private Character character;
public string Name => character.name == string.Empty ? null : character.name;
public void Update()

RaisePropertyChanged(string.Empty);


public event PropertyChangedEventHandler PropertyChanged;

public void RaisePropertyChanged([CallerMemberName]string propName = null)

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));











share|improve this question






























    1















    I'm using x:Bind and INotifyPropertyChanged to update UI in UWP application. But it behaves like OneTime binding even though I set it to OneWay.



    Bindings.Update() works, but I want to know why INotifyPropertyChanged fails.



    XAML



    <TextBlock Text="x:Bind staffVM.Name, Mode=OneWay"/>


    Code-behind:



    private StaffViewModel staffVM;
    private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)

    // I want to change staffVM according to ListView's selection.
    staffVM = staffListView.SelectedItem as StaffViewModel;
    staffVM.Update(); // If change this to Bindings.Update(), It works.



    ViewModel:



    public class StaffViewModel: INotifyPropertyChanged

    private Character character;
    public string Name => character.name == string.Empty ? null : character.name;
    public void Update()

    RaisePropertyChanged(string.Empty);


    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged([CallerMemberName]string propName = null)

    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));











    share|improve this question


























      1












      1








      1








      I'm using x:Bind and INotifyPropertyChanged to update UI in UWP application. But it behaves like OneTime binding even though I set it to OneWay.



      Bindings.Update() works, but I want to know why INotifyPropertyChanged fails.



      XAML



      <TextBlock Text="x:Bind staffVM.Name, Mode=OneWay"/>


      Code-behind:



      private StaffViewModel staffVM;
      private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)

      // I want to change staffVM according to ListView's selection.
      staffVM = staffListView.SelectedItem as StaffViewModel;
      staffVM.Update(); // If change this to Bindings.Update(), It works.



      ViewModel:



      public class StaffViewModel: INotifyPropertyChanged

      private Character character;
      public string Name => character.name == string.Empty ? null : character.name;
      public void Update()

      RaisePropertyChanged(string.Empty);


      public event PropertyChangedEventHandler PropertyChanged;

      public void RaisePropertyChanged([CallerMemberName]string propName = null)

      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));











      share|improve this question
















      I'm using x:Bind and INotifyPropertyChanged to update UI in UWP application. But it behaves like OneTime binding even though I set it to OneWay.



      Bindings.Update() works, but I want to know why INotifyPropertyChanged fails.



      XAML



      <TextBlock Text="x:Bind staffVM.Name, Mode=OneWay"/>


      Code-behind:



      private StaffViewModel staffVM;
      private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)

      // I want to change staffVM according to ListView's selection.
      staffVM = staffListView.SelectedItem as StaffViewModel;
      staffVM.Update(); // If change this to Bindings.Update(), It works.



      ViewModel:



      public class StaffViewModel: INotifyPropertyChanged

      private Character character;
      public string Name => character.name == string.Empty ? null : character.name;
      public void Update()

      RaisePropertyChanged(string.Empty);


      public event PropertyChangedEventHandler PropertyChanged;

      public void RaisePropertyChanged([CallerMemberName]string propName = null)

      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));








      c# mvvm uwp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 16:15









      Martin Zikmund

      27.2k6 gold badges42 silver badges65 bronze badges




      27.2k6 gold badges42 silver badges65 bronze badges










      asked Mar 25 at 12:11









      KirizKiriz

      851 silver badge8 bronze badges




      851 silver badge8 bronze badges






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Firstly, you need to specify the name of the variable that you want to update:



          public void Update()

          RaisePropertyChanged(nameof(Name));



          Documentation and sample: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.inotifypropertychanged.propertychanged



          Secondly, by default x:Bind is OneTime
          To fix it, add Mode="OneWay"




          Mode Specifies the binding mode, as one of these strings: "OneTime", "OneWay", or "TwoWay". The default is "OneTime". Note that this differs from the default for Binding, which is "OneWay" in most cases.




          Please read documentation
          https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/x-bind-markup-extension






          share|improve this answer

























          • 1. The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. according to your documentation in first part. 2. I've already set Mode="OneWay"

            – Kiriz
            Mar 25 at 13:41












          • Ok, next question is what are you expect? I cannot see in your code any changes that affect UI. Just Update method where you do nothing just invoke Property changed. But none of the properties changed. You need to change property and only after that invoke property changed event

            – Yauhen Sampir
            Mar 26 at 6:55


















          0














          The problem here is not on the level of the StaffViewModel class, but on the level of the page. When you do:



          staffVM = staffListView.SelectedItem as StaffViewModel;


          The UI has no notification about the fact that the staffVM field has changed. So the binding is still pointing to the old instance of StaffViewModel. Hence when you do staffVM.Update(), it does notify about changes, but the UI is not listening to that instance - it is still listening to notifications on the first selected item. Bindings.Update() fixes this because it completely re-evaluates all bindings so it will "get" the new value of staffVM field.



          Solution would be to implement INotifyPropertyChanged on the Page and encapsulate the staffVM in a property which raises PropertyChanged event.



          Ideally I would however suggest creating a "root" view model, which you will set only once and will not change and which will contain the selected item as its property. This way you don't have to implement INotifyPropertyChanged in the Page and its code-behind will be simpler. As a result you will have something like the following in the code-behind:



          public RootViewModel VM get; = new RootViewModel();


          And in XAML:



          <TextBlock Text="x:Bind VM.SelectedStaff.Name, Mode=OneWay"/>





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337531%2fxbind-ui-not-update-when-propertychanged-in-uwp%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Firstly, you need to specify the name of the variable that you want to update:



            public void Update()

            RaisePropertyChanged(nameof(Name));



            Documentation and sample: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.inotifypropertychanged.propertychanged



            Secondly, by default x:Bind is OneTime
            To fix it, add Mode="OneWay"




            Mode Specifies the binding mode, as one of these strings: "OneTime", "OneWay", or "TwoWay". The default is "OneTime". Note that this differs from the default for Binding, which is "OneWay" in most cases.




            Please read documentation
            https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/x-bind-markup-extension






            share|improve this answer

























            • 1. The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. according to your documentation in first part. 2. I've already set Mode="OneWay"

              – Kiriz
              Mar 25 at 13:41












            • Ok, next question is what are you expect? I cannot see in your code any changes that affect UI. Just Update method where you do nothing just invoke Property changed. But none of the properties changed. You need to change property and only after that invoke property changed event

              – Yauhen Sampir
              Mar 26 at 6:55















            0














            Firstly, you need to specify the name of the variable that you want to update:



            public void Update()

            RaisePropertyChanged(nameof(Name));



            Documentation and sample: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.inotifypropertychanged.propertychanged



            Secondly, by default x:Bind is OneTime
            To fix it, add Mode="OneWay"




            Mode Specifies the binding mode, as one of these strings: "OneTime", "OneWay", or "TwoWay". The default is "OneTime". Note that this differs from the default for Binding, which is "OneWay" in most cases.




            Please read documentation
            https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/x-bind-markup-extension






            share|improve this answer

























            • 1. The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. according to your documentation in first part. 2. I've already set Mode="OneWay"

              – Kiriz
              Mar 25 at 13:41












            • Ok, next question is what are you expect? I cannot see in your code any changes that affect UI. Just Update method where you do nothing just invoke Property changed. But none of the properties changed. You need to change property and only after that invoke property changed event

              – Yauhen Sampir
              Mar 26 at 6:55













            0












            0








            0







            Firstly, you need to specify the name of the variable that you want to update:



            public void Update()

            RaisePropertyChanged(nameof(Name));



            Documentation and sample: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.inotifypropertychanged.propertychanged



            Secondly, by default x:Bind is OneTime
            To fix it, add Mode="OneWay"




            Mode Specifies the binding mode, as one of these strings: "OneTime", "OneWay", or "TwoWay". The default is "OneTime". Note that this differs from the default for Binding, which is "OneWay" in most cases.




            Please read documentation
            https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/x-bind-markup-extension






            share|improve this answer















            Firstly, you need to specify the name of the variable that you want to update:



            public void Update()

            RaisePropertyChanged(nameof(Name));



            Documentation and sample: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.inotifypropertychanged.propertychanged



            Secondly, by default x:Bind is OneTime
            To fix it, add Mode="OneWay"




            Mode Specifies the binding mode, as one of these strings: "OneTime", "OneWay", or "TwoWay". The default is "OneTime". Note that this differs from the default for Binding, which is "OneWay" in most cases.




            Please read documentation
            https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/x-bind-markup-extension







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 25 at 12:33

























            answered Mar 25 at 12:27









            Yauhen SampirYauhen Sampir

            3202 silver badges9 bronze badges




            3202 silver badges9 bronze badges












            • 1. The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. according to your documentation in first part. 2. I've already set Mode="OneWay"

              – Kiriz
              Mar 25 at 13:41












            • Ok, next question is what are you expect? I cannot see in your code any changes that affect UI. Just Update method where you do nothing just invoke Property changed. But none of the properties changed. You need to change property and only after that invoke property changed event

              – Yauhen Sampir
              Mar 26 at 6:55

















            • 1. The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. according to your documentation in first part. 2. I've already set Mode="OneWay"

              – Kiriz
              Mar 25 at 13:41












            • Ok, next question is what are you expect? I cannot see in your code any changes that affect UI. Just Update method where you do nothing just invoke Property changed. But none of the properties changed. You need to change property and only after that invoke property changed event

              – Yauhen Sampir
              Mar 26 at 6:55
















            1. The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. according to your documentation in first part. 2. I've already set Mode="OneWay"

            – Kiriz
            Mar 25 at 13:41






            1. The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. according to your documentation in first part. 2. I've already set Mode="OneWay"

            – Kiriz
            Mar 25 at 13:41














            Ok, next question is what are you expect? I cannot see in your code any changes that affect UI. Just Update method where you do nothing just invoke Property changed. But none of the properties changed. You need to change property and only after that invoke property changed event

            – Yauhen Sampir
            Mar 26 at 6:55





            Ok, next question is what are you expect? I cannot see in your code any changes that affect UI. Just Update method where you do nothing just invoke Property changed. But none of the properties changed. You need to change property and only after that invoke property changed event

            – Yauhen Sampir
            Mar 26 at 6:55













            0














            The problem here is not on the level of the StaffViewModel class, but on the level of the page. When you do:



            staffVM = staffListView.SelectedItem as StaffViewModel;


            The UI has no notification about the fact that the staffVM field has changed. So the binding is still pointing to the old instance of StaffViewModel. Hence when you do staffVM.Update(), it does notify about changes, but the UI is not listening to that instance - it is still listening to notifications on the first selected item. Bindings.Update() fixes this because it completely re-evaluates all bindings so it will "get" the new value of staffVM field.



            Solution would be to implement INotifyPropertyChanged on the Page and encapsulate the staffVM in a property which raises PropertyChanged event.



            Ideally I would however suggest creating a "root" view model, which you will set only once and will not change and which will contain the selected item as its property. This way you don't have to implement INotifyPropertyChanged in the Page and its code-behind will be simpler. As a result you will have something like the following in the code-behind:



            public RootViewModel VM get; = new RootViewModel();


            And in XAML:



            <TextBlock Text="x:Bind VM.SelectedStaff.Name, Mode=OneWay"/>





            share|improve this answer



























              0














              The problem here is not on the level of the StaffViewModel class, but on the level of the page. When you do:



              staffVM = staffListView.SelectedItem as StaffViewModel;


              The UI has no notification about the fact that the staffVM field has changed. So the binding is still pointing to the old instance of StaffViewModel. Hence when you do staffVM.Update(), it does notify about changes, but the UI is not listening to that instance - it is still listening to notifications on the first selected item. Bindings.Update() fixes this because it completely re-evaluates all bindings so it will "get" the new value of staffVM field.



              Solution would be to implement INotifyPropertyChanged on the Page and encapsulate the staffVM in a property which raises PropertyChanged event.



              Ideally I would however suggest creating a "root" view model, which you will set only once and will not change and which will contain the selected item as its property. This way you don't have to implement INotifyPropertyChanged in the Page and its code-behind will be simpler. As a result you will have something like the following in the code-behind:



              public RootViewModel VM get; = new RootViewModel();


              And in XAML:



              <TextBlock Text="x:Bind VM.SelectedStaff.Name, Mode=OneWay"/>





              share|improve this answer

























                0












                0








                0







                The problem here is not on the level of the StaffViewModel class, but on the level of the page. When you do:



                staffVM = staffListView.SelectedItem as StaffViewModel;


                The UI has no notification about the fact that the staffVM field has changed. So the binding is still pointing to the old instance of StaffViewModel. Hence when you do staffVM.Update(), it does notify about changes, but the UI is not listening to that instance - it is still listening to notifications on the first selected item. Bindings.Update() fixes this because it completely re-evaluates all bindings so it will "get" the new value of staffVM field.



                Solution would be to implement INotifyPropertyChanged on the Page and encapsulate the staffVM in a property which raises PropertyChanged event.



                Ideally I would however suggest creating a "root" view model, which you will set only once and will not change and which will contain the selected item as its property. This way you don't have to implement INotifyPropertyChanged in the Page and its code-behind will be simpler. As a result you will have something like the following in the code-behind:



                public RootViewModel VM get; = new RootViewModel();


                And in XAML:



                <TextBlock Text="x:Bind VM.SelectedStaff.Name, Mode=OneWay"/>





                share|improve this answer













                The problem here is not on the level of the StaffViewModel class, but on the level of the page. When you do:



                staffVM = staffListView.SelectedItem as StaffViewModel;


                The UI has no notification about the fact that the staffVM field has changed. So the binding is still pointing to the old instance of StaffViewModel. Hence when you do staffVM.Update(), it does notify about changes, but the UI is not listening to that instance - it is still listening to notifications on the first selected item. Bindings.Update() fixes this because it completely re-evaluates all bindings so it will "get" the new value of staffVM field.



                Solution would be to implement INotifyPropertyChanged on the Page and encapsulate the staffVM in a property which raises PropertyChanged event.



                Ideally I would however suggest creating a "root" view model, which you will set only once and will not change and which will contain the selected item as its property. This way you don't have to implement INotifyPropertyChanged in the Page and its code-behind will be simpler. As a result you will have something like the following in the code-behind:



                public RootViewModel VM get; = new RootViewModel();


                And in XAML:



                <TextBlock Text="x:Bind VM.SelectedStaff.Name, Mode=OneWay"/>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 16:10









                Martin ZikmundMartin Zikmund

                27.2k6 gold badges42 silver badges65 bronze badges




                27.2k6 gold badges42 silver badges65 bronze badges



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337531%2fxbind-ui-not-update-when-propertychanged-in-uwp%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현