How can we improve the Windows dev platform?

Compilation of {x:Bind} to a global / static ViewModel fails when using Mode OneWay or TwoWay

Compilation fails with error CS1061 in MainPage.g.cs: "MainPage.MainPage_obj1_Bindings" does not contain a definition for "bindingsTracking" and no extension method "bindingsTracking" accepting a first argument of type "MainPage.MainPage_obj1_Bindings" could be found.

This is the same error that was marked Completed here:

https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/19316077-compilation-of-x-bind-to-static-fields-fails-if

5 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Dennis shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    3 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Dennis commented  ·   ·  Flag as inappropriate

        The project I am having the issue with was using Windows Template Studio with a target version of Win10 Build 17134 and a min of Win 10 Build 105063. However to simply demonstrate the bug, please do the following.

        1. Using VS2017 ver. 15.7.3 create a new Universal Windows Blank App named Test.

        2. Set both Target and Min version to Windows 10, version 1803 (10.0; Build 17134).

        3. Add the class Person.

        public class Person : INotifyPropertyChanged
        {
        private string name;
        public event PropertyChangedEventHandler PropertyChanged;

        public Person(string value)
        {
        name = value;
        }

        public string PersonName
        {
        get { return name; }
        set
        {
        name = value;
        OnPropertyChanged("PersonName");
        }
        }

        protected void OnPropertyChanged(string name)
        {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
        }

        4. Add the class MainViewModel.

        public class MainViewModel
        {
        public Person Person { get; set; }

        public MainViewModel()
        {
        Person = new Person("Dennis");
        }
        }

        5. In App.xaml.cs add:

        public static MainViewModel ViewModel { get; } = new MainViewModel();

        6. In MainPage.xaml add:

        xmlns:vm="using:Test"

        and in the Grid add:

        <TextBlock Text="{x:Bind vm:App.ViewModel.Person.PersonName}"/>

        If you build the solution, everything works. Now change the TextBlock to:

        <TextBlock Text="{x:Bind vm:App.ViewModel.Person.PersonName, Mode=OneWay}"/>

        Build again and you will get a CS1061 error of:

        'MainPage.MainPage_obj1_Bindings' does not contain a definition for 'bindingsTracking' and no extension method 'bindingsTracking' accepting a first argument of type 'MainPage.MainPage_obj1_Bindings' could be found (are you missing a using directive or an assembly reference?)

      Feedback and Knowledge Base