Binding works in Blend but not in Unity
Hi Guys,
I created a template which binds to a viewmodel. It works perfectly in Blend. It will also render in the unity editor if I eliminate the bindings and put the values in directly. In my template, I am using an ItemsControl. When I bind the values to the ViewModel it no longer works. I made sure that I am using an ObservableCollection and INotifyPropertyChanged as you demosntrated in your samples. Here goes the template:
Am I doing something wrong with the Binding? Please let me know.
Thanks
I created a template which binds to a viewmodel. It works perfectly in Blend. It will also render in the unity editor if I eliminate the bindings and put the values in directly. In my template, I am using an ItemsControl. When I bind the values to the ViewModel it no longer works. I made sure that I am using an ObservableCollection and INotifyPropertyChanged as you demosntrated in your samples. Here goes the template:
Code: Select all
<Style TargetType="ProgressBar" x:Key="ProgressBarStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<!-- attach the view model -->
<local:SegmentedProgressBarViewModel.Attach>
<local:SegmentedProgressBarViewModel HoleSizeFactor="0.7"/>
</local:SegmentedProgressBarViewModel.Attach>
<Ellipse Width="{Binding Diameter}" Height="{Binding Diameter}" VerticalAlignment="Stretch" Fill="{x:Null}"
StrokeThickness="220">
<Ellipse.Stroke>
<RadialGradientBrush>
<GradientStop Color="White" Offset="0.776"/>
<GradientStop Color="#FFe9b353" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Stroke>
</Ellipse>
<!-- render the segments -->
<ItemsControl ItemsSource="{Binding Segments}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<local:PiePiece CentreX="{Binding Parent.CentreX}" CentreY="{Binding Parent.CentreY}"
RotationAngle="{Binding StartAngle}" WedgeAngle="{Binding WedgeAngle}"
Radius="{Binding Parent.Radius}" InnerRadius="{Binding Parent.InnerRadius}"
Fill="{x:Null}" Stroke="White" Opacity="0.5"/>
<local:PiePiece CentreX="{Binding Parent.CentreX}" CentreY="{Binding Parent.CentreY}"
RotationAngle="{Binding StartAngle}" WedgeAngle="{Binding WedgeAngle}"
Radius="{Binding Parent.Radius}" InnerRadius="{Binding Parent.InnerRadius}" Stroke="White" Opacity="{Binding Opacity}" Fill="#7F000000" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Thanks

-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Binding works in Blend but not in Unity
If it is working in Blend it would probably be a bug in Noesis or something we haven't implemented yet.
Could you please post here the SegmentedProgressBarViewModel and PiePiece classes, so I can debug the sample and find what is failing?
Could you please post here the SegmentedProgressBarViewModel and PiePiece classes, so I can debug the sample and find what is failing?
Re: Binding works in Blend but not in Unity
Hi sfernandez.
I found a solution to the issue. I used {Binding ElementName=Root, Path=DataContext.XXX} to get the datacontext of the parent. Here is the code.
This code above works! There seems to be an issue with Noesis using "Parent.XXX" to get the context. For example {Binding Parent.XXX}.
Let me know what you think.
Thanks!!
I found a solution to the issue. I used {Binding ElementName=Root, Path=DataContext.XXX} to get the datacontext of the parent. Here is the code.
Code: Select all
<Style TargetType="ProgressBar" x:Key="ProgressBarStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<!-- attach the view model -->
<local:SegmentedProgressBarViewModel.Attach>
<local:SegmentedProgressBarViewModel HoleSizeFactor="0.7"/>
</local:SegmentedProgressBarViewModel.Attach>
<Ellipse Width="{Binding Diameter}" Height="{Binding Diameter}" VerticalAlignment="Stretch" Fill="{x:Null}"
StrokeThickness="220">
<Ellipse.Stroke>
<RadialGradientBrush>
<GradientStop Color="White" Offset="0.776"/>
<GradientStop Color="#FFe9b353" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Stroke>
</Ellipse>
<!-- render the segments -->
<ItemsControl x:Name="Root" ItemsSource="{Binding Segments}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<local:PiePiece CentreX="{Binding ElementName=Root, Path=DataContext.CentreX}" CentreY="{Binding ElementName=Root, Path=DataContext.CentreY}"
RotationAngle="{Binding StartAngle}" WedgeAngle="{Binding WedgeAngle}"
Radius="{Binding ElementName=Root, Path=DataContext.Radius}" InnerRadius="{Binding ElementName=Root, Path=DataContext.InnerRadius}"
Fill="{x:Null}" Stroke="White" Opacity="0.5"/>
<local:PiePiece CentreX="{Binding ElementName=Root, Path=DataContext.CentreX}" CentreY="{Binding ElementName=Root, Path=DataContext.CentreY}"
RotationAngle="{Binding StartAngle}" WedgeAngle="{Binding WedgeAngle}"
Radius="{Binding ElementName=Root, Path=DataContext.Radius}" InnerRadius="{Binding ElementName=Root, Path=DataContext.InnerRadius}"
Fill="#66000000" Stroke="White" Opacity="{Binding Opacity}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Let me know what you think.
Thanks!!
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Binding works in Blend but not in Unity
When you typed "Parent." in the binding you meant the FrameworkElement.Parent property?
I'm afraid that property is not exposed, that's why it didn't work with your first code.
Anyway, in that example Parent will point to the Grid just before the PiePiece elements. Are you sure your initial code was working in Blend?
Is there any chance I can get that code to see what was going there, I'm curious how WPF solved that.
I'm afraid that property is not exposed, that's why it didn't work with your first code.
Anyway, in that example Parent will point to the Grid just before the PiePiece elements. Are you sure your initial code was working in Blend?
Is there any chance I can get that code to see what was going there, I'm curious how WPF solved that.
Re: Binding works in Blend but not in Unity
Hi sfernandez,
I created a demo app to demonstrate the binding. Can you email me @ mrtouya@msn.com and I will send you a zip file with the code.
Thanks
I created a demo app to demonstrate the binding. Can you email me @ mrtouya@msn.com and I will send you a zip file with the code.
Thanks

Re: Binding works in Blend but not in Unity
Hi Jsantos,
I created the issue in bug tracker. Are you able to access everything you need? The issue ID is 0001052.
Let me know.
Thanks!
I created the issue in bug tracker. Are you able to access everything you need? The issue ID is 0001052.
Let me know.
Thanks!
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Binding works in Blend but not in Unity
Hi,
We were able to download your project, thanks for your cooperation.
We will take a look and follow the communication in the bugtracker.
We were able to download your project, thanks for your cooperation.
We will take a look and follow the communication in the bugtracker.
Who is online
Users browsing this forum: Google [Bot] and 0 guests