vaninadisc
Topic Author
Posts: 10
Joined: 10 Mar 2017, 08:23

Can't get simple binding to work in one particular case

12 Apr 2017, 08:43

I'm down to what I think is my last bit of learning curve, but I'm still having a great time with Noesis so far. At any rate, my problem is that I can't get x:Name within-control binding to work in a particular (common) situation.

This is with Noesis 2.0, Unity 5.5.

Here's a custom control with simple binding. It works just fine if I load this xaml DIRECTLY into a NoesisView.
<UserControl
	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" mc:Ignorable="d" 
	x:Class="ComboCollectionXaml.MultiSlateMenu"
	x:Name="MultiSlateMenuControl">
    
    <StackPanel>
        <TextBox x:Name="textbox" />
        <Label Content="{Binding Text, ElementName=textbox}" />
    </StackPanel>
            
</UserControl>
However, I am using this UserControl like a Page. My NoesisView loads a WindowLoader control, who has the job of just displaying a different content control when we want to switch to a different menu page.
Something like this-
<UserControl
	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" mc:Ignorable="d"
    xmlns:ccx="clr-namespace:ComboCollectionXaml"
	x:Class="ComboCollectionXaml.WindowLoader"
	x:Name="WindowLoaderControl">
 
    <UserControl.Resources>
             <DataTemplate DataType="{x:Type ccx:MainMenuViewModel}"><ccx:MainMenu/></DataTemplate>
             <DataTemplate DataType="{x:Type ccx:MultiSlateMenuViewModel}"><ccx:MultiSlateMenu/></DataTemplate>
    </UserControl.Resources>


    <Grid>       
        <ContentControl Content="{Binding MainViewModel}"/>
    </Grid>

</UserControl>
Then the WindowLoader viewmodel simply changes MainViewModel to different "top level" viewmodels (the ones listed above in UserControl.Resources). Everything seems to work perfectly fine for this, other than binding. That is, when I go MainViewModel = new MultiSlateMenuViewModel(), that control appears exactly the same as it does when I just load it directly in NoesisView, but the textbox->label binding is broken.

I have a similar problem for new user controls with viewmodels that I just drop in, so I don't think it's because of the viewmodel binding. They are able to bind to the viewmodel, but basically anything off of x:Name again doesn't work.

Any help would be greatly appreciated. Thanks!
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Can't get simple binding to work in one particular case

12 Apr 2017, 14:21

Hi,

Nothing wrong on your side, I found a bug in our code. The problem appears when the root of a template is an element that has code-behind doing LoadComponent.

As a workaround, you can wrap the user control in the DataTemplate with a Border, for example:
<UserControl
	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" mc:Ignorable="d"
    xmlns:ccx="clr-namespace:ComboCollectionXaml"
	x:Class="ComboCollectionXaml.WindowLoader"
	x:Name="WindowLoaderControl">
 
    <UserControl.Resources>
             <DataTemplate DataType="{x:Type ccx:MainMenuViewModel}"><Border><ccx:MainMenu/></Border></DataTemplate>
             <DataTemplate DataType="{x:Type ccx:MultiSlateMenuViewModel}"><Border><ccx:MultiSlateMenu/></Border></DataTemplate>
    </UserControl.Resources>

    <Grid>       
        <ContentControl Content="{Binding MainViewModel}"/>
    </Grid>

</UserControl>
We will fix this issue for the next release.
 
vaninadisc
Topic Author
Posts: 10
Joined: 10 Mar 2017, 08:23

Re: Can't get simple binding to work in one particular case

12 Apr 2017, 18:06

Great! That fixed everything. I really appreciate the support level.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Can't get simple binding to work in one particular case

25 Apr 2017, 11:29

Fixed in NoesisGUI 2.0.1 version.

Who is online

Users browsing this forum: No registered users and 0 guests