mrtouya
Topic Author
Posts: 6
Joined: 03 Mar 2017, 16:32

Binding works in Blend but not in Unity

29 Mar 2017, 20:34

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:
<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>
Am I doing something wrong with the Binding? Please let me know.

Thanks :-)
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Binding works in Blend but not in Unity

30 Mar 2017, 11:11

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?
 
mrtouya
Topic Author
Posts: 6
Joined: 03 Mar 2017, 16:32

Re: Binding works in Blend but not in Unity

31 Mar 2017, 15:32

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.
<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>
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!!
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Binding works in Blend but not in Unity

03 Apr 2017, 12:36

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.
 
mrtouya
Topic Author
Posts: 6
Joined: 03 Mar 2017, 16:32

Re: Binding works in Blend but not in Unity

06 Apr 2017, 15:23

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 ;-)
 
User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Binding works in Blend but not in Unity

07 Apr 2017, 21:49

Could you create a new report in the tracker and attach there the project?

Thanks!
 
mrtouya
Topic Author
Posts: 6
Joined: 03 Mar 2017, 16:32

Re: Binding works in Blend but not in Unity

15 Apr 2017, 00:23

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!
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Binding works in Blend but not in Unity

18 Apr 2017, 13:04

Hi,

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: No registered users and 1 guest