[Unity] Nested Data Bindings
Hi,
I am trying to bind user controls nested within user controls, and it does not seem to be working.
Example:
DetailCardView.xaml
AtAGlanceView.xaml
Test.cs
So this works fine in DetailCardView, and the bindings work for the textblocks there, but does not work for the AtAGlance control. Is there something I'm missing here?
I am trying to bind user controls nested within user controls, and it does not seem to be working.
Example:
DetailCardView.xaml
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vs="clr-namespace:Assets.UI.VirtualShelf"
xmlns:vm="clr-namespace:Assets.UI.ViewModels.VirtualShelf"
x:Name="Root"
x:Class="Assets.UI.VirtualShelf.DetailCardView"
Margin="0,0,0,0">
<Grid>
<StackPanel>
<TextBlock Text="{Binding Category}"></TextBlock>
<TextBlock Text="{Binding AtAGlance.Name}"></TextBlock>
<vs:AtAGlanceView
DataContext="{Binding AtAGlance}"
Width="{Binding ActualWidth, ElementName=Root, Mode=OneWay}"
Height="{Binding ActualHeight, ElementName=Root, Mode=OneWay}" />
</StackPanel
</Grid>
</UserControl>
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Assets.UI.VirtualShelf.AtAGlanceView">
<Grid Background="White">
<TextBlock Text="{Binding Name}" />
</Grid>
</UserControl>
Code: Select all
public class DetailCardViewTestComponent : MonoBehaviour
{
public void Start()
{
var detailCard = GetComponent<NoesisGUIPanel>().GetRoot<DetailCardView>();
var vm = new DetailCardViewModel
{
Category = "Foo",
AtAGlance = new AtAGlanceViewModel
{
Name = "Bar"
}
};
}
}
Re: [Unity] Nested Data Bindings
Managed to get this working by using a ContentControl instead of setting DataContext on the custom control directly:
Code: Select all
<Grid>
<Grid.Resources>
<DataTemplate x:Key="AtAGlanceTemplate">
<vs:AtAGlanceView
DataContext="{Binding}"
Width="{Binding ActualWidth, ElementName=Root, Mode=OneWay}"
Height="{Binding ActualHeight, ElementName=Root, Mode=OneWay}" />
</DataTemplate>
</Grid.Resources>
<StackPanel>
<TextBlock Text="{Binding Category}"></TextBlock>
<TextBlock Text="{Binding AtAGlance.Name}"></TextBlock>
<ContentControl Content="{Binding AtAGlance}" ContentTemplate="{StaticResource AtAGlanceTemplate}" />
</StackPanel
</Grid>
-
-
sfernandez
Site Admin
- Posts: 2058
- Joined:
Re: [Unity] Nested Data Bindings
It is a bug, please create a ticket in our bugtracker and we will try to fix it for the 1.1.12 version.
Who is online
Users browsing this forum: No registered users and 0 guests