Right. So moving from WPF to UWP, I'm trying to use x:Bind
to get compile-time benefits. Simple scenarios work fine; however I have found a number of issues that I was not able to solve. They are all related, so I thought I'd post them in one place:
x:Bind
. I have set DataContext (as well as d:DataContext
just as we do in WPF) both in XAML and in the constructor, but it won't show members no matter what. Has anyone done this successfully?DataContext
is always set to Page
's code-behind (really??) and that I need to define a ViewModel type property in the code-behind and then use that property in x:Bind
. Is this correct? I tried it and it works but gives rise to the next question.PropertyChanged
notifications do not update the UI. For example, if the code-behind property is named Game
(of type GameVM
) and there is a public property in GameVM
named Player
(of type GamePlayer
), and in turn GamePlayer
contains a property named Name
, the x:Bind
path will look like {x:Bind Path=Game.Player.Name}
. But if I do this, any change notifications raised from within Name
property do not update Page's UI.One alternate I tried was to listen to PropertyChanged at each level and then bubble it up the hierarchy, but that hasn't worked. Even if it does, doing this seems a bit too much work. In WPF sub-properties like Game.Player.Name
work properly without having to doing property change bubbling. Or am I missing something?
x-bind allows you to set HTML attributes on elements based on the result of JavaScript expressions.
x:Bind for WPF in . NET Framework and . NET Core is still not supported.
Data binding is the process that establishes a connection between the UI layer with our Data Layer. So when you change your Data your GUI is updated and vice versa.
Many of the other UWP app samples also use a basic MVVM architecture, and the Traffic App sample includes both code-behind and MVVM versions, with notes describing the MVVM conversion.
Right. After playing with it for a few days and searching numerous references, here are my findings:
{x:Bind}
lacks design-time support. The feature is on the wishlist though. You may want to upvote it there.
(The new version of Visual Studio 15.4.4 does support Intellisense in {x:Bind}in the required way.){x:Bind}
uses code-behind as its DataContext. So you need to define a public property of your ViewModel type in the code-behind and then use it in your {x:Bind}
path.{x:Bind}
is OneTime
, unlike {Binding}
which uses OneWay
or TwoWay
in almost all cases. So you need to explicitly specify Mode
in your binding. People coming from WPF should take special care of it.{x:Bind}
. There is no need of bubbling these notifications upwards in the property hierarchy. The problem I was facing (#3 in the question) was because my sub-property was of type List<T>
. I changed it to ObservableCollection<T>
and it started working.Hope this works somebody down the road.
Well as a beginner, the only question I can answer for you is the first one. Intellisense does not work inside the {x:Bind}. The members are never shown there in UWP for some unknown reasons. As for the next two questions of yours, I am still working on them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With