- vaninadisc
- Posts: 10
- Joined:
Can't get simple binding to work in one particular case
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.
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-
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!
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.
Code: Select all
<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>
Something like this-
Code: Select all
<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>
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!
-
sfernandez
Site Admin
- Posts: 3005
- Joined:
Re: Can't get simple binding to work in one particular case
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:
We will fix this issue for the next release.
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:
Code: Select all
<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>
- vaninadisc
- Posts: 10
- Joined:
Re: Can't get simple binding to work in one particular case
Great! That fixed everything. I really appreciate the support level.
-
sfernandez
Site Admin
- Posts: 3005
- Joined:
Re: Can't get simple binding to work in one particular case
Fixed in NoesisGUI 2.0.1 version.
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 3 guests