c# - Master Detail MVVM with Prism and XAML binding view in data context -
i have following dummy application i'm trying build master detail 2 views. first collection view, can select element of , displays in content presenter data template textblock , textbox defined below.
i have tried move textblock , textbox out view, have been unsuccessful @ getting display data. if remove tbs , uncomment view, display view tbs in view won't populate.
of course, idea have more 1 type.
mainwindow
<window x:class="myapp.views.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:views="clr-namespace:myapp.views" mc:ignorable="d" xmlns:prism="http://prismlibrary.com/" xmlns:viewmodel="clr-namespace:myapp.viewmodels" prism:viewmodellocator.autowireviewmodel="true" title="mainwindow" height="350" width="525"> <grid x:name="layoutroot"> <stackpanel orientation="horizontal"> <views:collectionview datacontext="{binding myitemcollection}"> </views:collectionview> <contentpresenter x:name="detail" content="{binding myitemcollection.selectedviewmodel}"> <contentpresenter.resources> <datatemplate datatype="{x:type viewmodel:textviewmodel}"> <stackpanel> <textblock text="{binding name}"></textblock> <textbox text="{binding text}"></textbox> <!--<views:textview/>--> </stackpanel> </datatemplate> </contentpresenter.resources> </contentpresenter> </stackpanel> </grid> textview
<usercontrol x:class="myapp.views.textview" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:myapp.views" xmlns:viewmodel="clr-namespace:myapp.viewmodels" mc:ignorable="d" xmlns:prism="http://prismlibrary.com/" prism:viewmodellocator.autowireviewmodel="true" d:designheight="300" d:designwidth="300"> <grid> <stackpanel> <textblock text="text item"/> <textblock text="{binding name}"></textblock> <textbox text="{binding text}"></textbox> </stackpanel> </grid>
you need remove prism:viewmodellocator.autowireviewmodel="true" attribute textview.
what pulls appropriate view model container , assigns view model textview.datacontext. on other hand in template not explicitly pass templated data textview control, it's expected inherited via automatic inheritance of datacontext. not work, because textview.datacontext explicitly set prism:viewmodellocator.autowireviewmodel="true".
in case required use view model auto wiring can set attribute referencing scope, in xaml in view "used", e.g.:
<stackpanel> <views:textview prism:viewmodellocator.autowireviewmodel="true" /> </stackpanel>
Comments
Post a Comment