Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am struggling with XMLDataProvider resource and binding Usercontrols in WPF. I have an app with a dynamic amount of the same UserControl.This User control is called "Thruster_Control.xaml" and is a composition of 3 gauge controls. I want to bind the usercontrol values from an Xml file. My XML looks like this:

XML
<NMEA_MESSAGE>
<TRC id="1">
<rpm_value>10</rpm_value>
<pitch_value>10</pitch_value>
<rudder_value>10</rudder_value>
</TRC>
<TRC  id="2">
<rpm_value>58</rpm_value>
<pitch_value>0.6</pitch_value>
<rudder_value>19</rudder_value>
</TRC>
<rpm_value>35</rpm_value>
<pitch_value>2.58</pitch_value>
<rudder_value>30</rudder_value>
</TRC>

I declare it in the app resources

CSS
<XmlDataProvider x:Key="NMEA Source" Source="E:\CSharpProjects\Src\---s_Test\----\Input Data\Data\NMEA_Data_List.xml"  XPath="NMEA_MESSAGE/TRC" />


The 3 gauges in each Usercontrol looks like this one:


C#
<gauge:CircularGaugeControl x:Name="gauge_pitch" 
                                Radius="105"
                                ScaleRadius="60"
                                ScaleStartAngle="140"
                                ScaleSweepAngle="270"
                                PointerLength="55"
                                PointerCapRadius="15"
                                MinValue="0"
                                MaxValue="1"
                                MajorDivisionsCount="10"
                                MinorDivisionsCount="5"
                                OptimalRangeEndValue="0.8"
                                OptimalRangeStartValue="0.5"
                                CurrentValue="{Binding ElementName=pitch_value}"
                                RangeIndicatorThickness="9"
                                RangeIndicatorRadius="45"
                                RangeIndicatorLightRadius="8"
                                RangeIndicatorLightOffset="60"
                                ScaleLabelRadius="75"
                                ScaleLabelSize="40,20"
                                ScaleLabelFontSize="12"
                                ScaleLabelForeground="SlateGray"
                                MajorTickSize="10,3"
                                MinorTickSize="3,1"
                                MajorTickColor="White"
                                MinorTickColor="SlateGray"
                                ImageOffset="-50"
                                GaugeBackgroundColor="Black"
                                PointerThickness ="5"
                                DialTextOffset="40"
                                DialText="Pitch"
                                DialTextColor="SlateGray"
                                        
                                        />


If for example , I add to the grid of my app 2 Usercontrols ( which means 6 gauges) dynamically, I want to load the values from 2 nodes TRC.
I don't know if this is possible or should be an XML per User control . I checked many examples but they are only with one usercontrol and is a simple LISTBOX. I think it must be possible to bind multiple UserConrtols of the same type with one source.

Could someone suggest me a better performance ? or give me some guidelines about this?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900