Binding works in Blend but not in Unity
Posted: 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:
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