none
Usercontrol dependency property binding issue RRS feed

  • Question

  • in my project i wanted to have a split window , so one side of the window will always load set of usercontrols which has basically datagrid. the usercontrol is selected based on the current view model. its work fine. But when the user select an item from the dataview i would like to open another usercontrol in the other side of the window, which consist of lot of textboxes and combo boxes. The problem starts here am not able to bind any value to this usercontrol. i could see that the property is getting value but every fields remains empty.

    window.xaml

    <Window.resources>

           DataTemplate DataType="{x:Type vm:ViewModel1}" >
                  <loc:UserControl1  Items="{Binding Items}"  />
                 </DataTemplate>
            <DataTemplate DataType="{x:Type vm:ViewModel2}">
                <loc:UserControl2/>
            </DataTemplate>
            <DataTemplate DataType="{x:Type vm:ViewModel3}">
                <loc:UserContro3l/>
            </DataTemplate>
     </Window.resources>

    .

    .

    <ContentControl Content={Binding CurrentView}/> // works fine

    <Grid>

    <Grid.Resources>

    <DataTemplate DataType="{x:Type vm:ViewModel1}">      // All usercontrols displays But Data is not binding
                            <loc:UC1 BName="{Binding Path=BName}"/>// BName is not binding
                        </DataTemplate>
                        <DataTemplate DataType="{x:Type vm:ViewModel2}">
                            <loc:UC2/>
                        </DataTemplate>
                        <DataTemplate DataType="{x:Type ViewModel3}">
                            <loc:UC3/>
                        </DataTemplate>
       </Grid.Resources>

    </Grid>

    In the usercontrols i have created dependeny properties and in the view model properties to bind them.

    It will be great someone could tell me what am i doing wrong

    Wednesday, April 9, 2014 8:15 AM

Answers

  • I solved the issue by removing usercontrols and putting them in a resource dictiory. it works perfect.
    • Proposed as answer by Magnus (MM8)MVP Wednesday, April 9, 2014 2:49 PM
    • Marked as answer by Yang,Chenfei Thursday, April 10, 2014 1:13 AM
    Wednesday, April 9, 2014 2:31 PM

All replies