Goalmarkers Problem

Feb 15, 2014 at 5:26 AM
The situation: Multiple gauges on the window, but problem arises even with only one gauge.
        <gauge:Gauge Grid.Column="1"
                        FontSize="12" AutoScale="False" Value="{Binding CurrentT}"
                        StartAngle="-30" EndAngle="210" x:Name="TGauge" MajorTickCount="10" MinorTickCount="5" MinValue="{Binding TMin}" MaxValue="{Binding TMax}" ValueFormat="T: {}{0:F3}"
                        HorizontalAlignment="Left" Margin="326,10,0,0" Grid.Row="1" VerticalAlignment="Top" Height="100" Width="100">
           
            <gauge:Gauge.ValueTextStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="Foreground" Value="White"/>
                    <Setter Property="Margin" Value="0,60,0,0" />
                    <Setter Property="FontSize" Value="8"/>
                </Style>
            </gauge:Gauge.ValueTextStyle>

            <gauge:Gauge.TickLabelStyle>
                <Style TargetType="TextBlock">
                    <Setter Property="Foreground" Value="White"/>
                    <Setter Property="FontSize" Value="8"/>
                </Style>
            </gauge:Gauge.TickLabelStyle>
            <gauge:Gauge.GoalMarkers>
                <gauge:GoalMarker MarkerColor="Red" Value="2"/>
            </gauge:Gauge.GoalMarkers>
        </gauge:Gauge>
Error: at line "<gauge:GoalMarker MarkerColor="Red" Value="2"/>"
--> Specified element is already the logical child of another element. Disconnect it first.

What does this mean, and how do I fix it?
Coordinator
Feb 18, 2014 at 7:18 PM
Do you actually receive a run-time error, or is is just a design-time error? I am seeing a design-time error, although the code builds and is executable. Not sure why Visual Studio is giving the design-time error.
Apr 20, 2014 at 6:52 PM
any resolution to this issue?
Coordinator
Apr 21, 2014 at 7:16 PM
Again, do you actually receive a run-time error, or is is just a design-time error? I am seeing a design-time error, although the code builds and is executable. Not sure why Visual Studio is giving the design-time error. The control does not already have a logical parent.
Apr 22, 2014 at 1:18 AM
Yes, I do get a run-time error with multiple gauges.
Coordinator
Apr 22, 2014 at 3:51 AM
Could you post your code? Thanks!
Apr 22, 2014 at 11:39 AM
It throws an exception in the GoalMarkers_CollectionChanged event:

//Code behind in wpfgauge.xaml.cs
private void GoalMarkers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        if(e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            foreach (GoalMarker gm in e.NewItems)
            {
                gm.ParentGauge = this;
                gm.GaugeMax = this.MaxValue;
                gm.GaugeStartAngle = this.StartAngle;
                gm.GaugeEndAngle = this.EndAngle;

                //GoalMarker gm2 = new GoalMarker();
                //gm2.ParentGauge = gm.ParentGauge;
                //gm2.GaugeMax = gm.GaugeMax;
                //gm2.GaugeStartAngle = gm.GaugeStartAngle;
                //gm2.GaugeEndAngle = gm.GaugeEndAngle;

                GoalMarkerLayout.Children.Add(gm);
            }
    } 

<!--XAML--> <gg:Gauge Grid.Column="1"
                    FontSize="12" AutoScale="False" Value="1250"
                    x:Name="TGauge" MajorTickCount="10" MinorTickCount="5" MinValue="0" MaxValue="5000" 
                    HorizontalAlignment="Left"  StartAngle="-65" EndAngle="247" MajorTickMarkColor="LightYellow" Margin="0" Grid.Row="1" VerticalAlignment="Top" Height="200" Width="200">
                            <gg:Gauge.GoalMarkers>
                                <gg:GoalMarker MarkerColor="Red" Value="2000"></gg:GoalMarker>
                            </gg:Gauge.GoalMarkers>
                            <gg:Gauge.ValueTextStyle>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="Margin" Value="0,60,0,0" />
                            <Setter Property="FontSize" Value="12"/>
                        </Style>
                    </gg:Gauge.ValueTextStyle>

                    <gg:Gauge.TickLabelStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="FontSize" Value="12"/>
                        </Style>
                    </gg:Gauge.TickLabelStyle>

                </gg:Gauge>
                    </StackPanel>
                    <StackPanel>
                        <gg:Gauge Grid.Column="1"
                    FontSize="12" AutoScale="False" Value="150"
                    StartAngle="-65" EndAngle="247" MajorTickMarkColor="LightYellow"  x:Name="TGauge2" MajorTickCount="10" MinorTickCount="5" MinValue="0" MaxValue="500" 
                    HorizontalAlignment="Left"  Margin="0" Grid.Row="1" VerticalAlignment="Top" Height="200" Width="200">
                            <gg:Gauge.GoalMarkers>
                                <gg:GoalMarker MarkerColor="Red" Value="200"></gg:GoalMarker>
                            </gg:Gauge.GoalMarkers>
                            <gg:Gauge.ValueTextStyle>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Margin" Value="0,50,0,0"></Setter>
                                    <Setter Property="Foreground" Value="#fff" />
                                    <Setter Property="FontSize" Value="15" />
                                    <Setter Property="FontWeight" Value="Bold" />
                                    <Setter Property="FontFamily" Value="Tahoma" />
                                </Style>
                            </gg:Gauge.ValueTextStyle>

                            <gg:Gauge.TickLabelStyle>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="FontSize" Value="12"/>
                                </Style>
                            </gg:Gauge.TickLabelStyle>

                        </gg:Gauge>
Coordinator
Apr 23, 2014 at 2:58 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Apr 23, 2014 at 3:08 AM
The issue reported by powers60 has been resolved. See changeset 33505 for details.