tag:blogger.com,1999:blog-6425054342484936402.post4807419008631949832..comments2023-06-10T06:42:33.406-05:00Comments on Adventures in Mobile: Navigation With MVVMAdam Kemphttp://www.blogger.com/profile/06909381951179789649noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-6425054342484936402.post-77436621662208153412016-04-08T00:27:10.695-05:002016-04-08T00:27:10.695-05:00Thanks for the clarification, I got my terminology...Thanks for the clarification, I got my terminology mixed up.<br /><br />Also, thanks for answering my question, this clears things up quite a lot. On reflection, I don't have a good reason to keep knowledge of the view model, or model in my case, from the view. I am suffering from a bit of information overload as I have only been learning C# for a couple of weeks, so trying to get my head around a new language + the MVVM pattern is a fairly steep learning curve, but it is becoming a lot clearer to me, with help from people like yourself.<br /><br />Thanks again.Danhttps://www.blogger.com/profile/04035746281421991189noreply@blogger.comtag:blogger.com,1999:blog-6425054342484936402.post-6487280248670949132016-04-07T20:04:42.616-05:002016-04-07T20:04:42.616-05:00First, a clarification. A "bindable property&...First, a clarification. A "bindable property" is a property that can be a target for binding. For instance, ListView.ItemsSourceProperty is a BindableProperty because you can call SetBinding using it as the property to bind. The source (the property in your view model) does not need to be bindable. Simply implementing INotifyPropertyChanged does not make a property "bindable", it just makes it suitable as a source for a binding. So you shouldn't call that a "bindable property".<br /><br />As to your question, I think I need to question one of your premises: "The view has no knowledge of the WidgetDataModel class, so I cannot use that type." Why not? It's appropriate, and typical, for a view to have knowledge of the view model. It's certainly not required since binding is done by name, and reflection is used to find the CLR properties, but there's no reason you can't make your view explicitly aware of the view model type. The view model should never be aware of the view, but the view can (and very often does) know about the view model.<br /><br />So my recommendation would be to make your new bindable property in your view use the type that's appropriate.<br /><br />The ItemsSource property in ListView (actually in ItemsView) simply uses the non-generic IEnumerable type (IEnumerable extends IEnumerable). If there were a situation where you needed a view to be entirely agnostic about the type of its BindingContext then that is basically how you do it. Just don't use a generic collection type that forces you to specify the type of element.Adam Kemphttps://www.blogger.com/profile/06909381951179789649noreply@blogger.comtag:blogger.com,1999:blog-6425054342484936402.post-90818255027611556122016-04-06T20:57:59.000-05:002016-04-06T20:57:59.000-05:00Hi Adam, firstly thanks for this post, I like the ...Hi Adam, firstly thanks for this post, I like the solution you have put forward for navigating with MVVM design pattern. I have a question regarding data binding of properties that is related to this implementation, and keeping the view as "dumb" as possible. <br /><br />I have a property in my view model (WidgetData) which is of type Queue<WidgetDataModel>. The viewmodel exposes this as a bindable property by conforming to the INotifyPropertyChanged interface and raising the PropertyChanged event when the property is updated. <br /><br />I have a number of views that use this property, one being a ListView. In the case of the ListView I can simply call SetBinding(ListView.ItemSourceProperty, "WidgetData") to bind the lists ItemSourceProperty to the WidgetData. This works fine. <br /><br />However, I have another view that needs to process the data a bit more, which means I cant simply bind it to a predefined BindableProperty, so I am trying to create my own. This is where I hit the issue. If I create a BindableProperty, it seems that I need to pass it a returnType on construction. The view has no knowledge of the WidgetDataModel class, so I cannot use that type. I have tried to pass it Queue<object> type, or just object type, but this seems to cause the binding to fail.<br /><br />The workaround I have come up with is to make the WidgetData property of type Queue<IDictionary<string,object>>, then reference the elements I need in the binding by using [key]. This works but I am wondering how the ListView.ItemSourceProperty is constructed, as this must be constructed in some sort of generic way for the binding to work correctly.<br /><br />Apologies if this is not the right place to post - please remove if not.<br /><br />Many thanks, Dan.Danhttps://www.blogger.com/profile/04035746281421991189noreply@blogger.com