Loading Gauge via XML dynamically

Gauge for WPF Forum

Posted 14 years ago by Daniel Koslowski
Version: 10.1.0523
Avatar
Hello,

Is there a possibility to load actipro gauges dynamically at runtime?
Container for these gauges would be an xml file. Is there a simple way to achieve that?

My first approach:

  XmlTextReader r = new XmlTextReader("Controls.xml");
  XElement controls = XElement.Load(r);

  var gauges = controls.Elements("Gauges");
  var gauge = (from g in gauges.Elements()                                             
               where g.Attribute("Name").Value == "Linear_Gauge"                        
               select g).First();                                                      
        
  LinearGauge lg = (LinearGauge) XamlReader.Load(gauge.CreateReader());
leads me to a type converter error of the LinearGauge.

So how can I access the LinearGauge type Converter ??
Or perhaps there is an easier way to load the gauge ?? ... Any help would be highly appreciated.

Comments (6)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Daniel,

You can certainly load any of our Gauges control dynamically using a XamlReader, just like any native WPF control. But, the XamlReader would need to be passed a valid "XAML" file/reader, which includes the xmlns declarations at the top. Based on your code, it doesn't look like you are including that.


Actipro Software Support

Posted 14 years ago by Daniel Koslowski
Avatar
Hello and thank you for the quick reply.
Actually the xml namespace declaration I currently pass to the XamlReader is:

xmlns:gauge="http://schemas.actiprosoftware.com/winfx/xaml/gauge"
Is there any other namespace declaration needed?
The XElement I get via LINQ out of my example Controls.xml looks like:

<gauge:LinearGauge Name="Linear_Gauge" xmlns:gauge="http://schemas.actiprosoftware.com/winfx/xaml/gauge"> 
      <gauge:LinearScale>
            <gauge:LinearTickSet>
                  <gauge:LinearTickSet.Pointers>
                      <gauge:LinearPointerMarker CanDrag="True" Value="40" />
                  </gauge:LinearTickSet.Pointers>
                  <gauge:LinearTickSet.Ticks>
                      <gauge:LinearTickMarkMinor Background="Black" />
                      <gauge:LinearTickMarkMajor Background="Black" />
                      <gauge:LinearTickLabelMajor FontSize="10px" />
                  </gauge:LinearTickSet.Ticks>
              </gauge:LinearTickSet>
      </gauge:LinearScale>
</gauge:LinearGauge>
The error message I get:
Quote:

The elementtype "ActiproSoftware.Windows.Controls.Gauge.LinearGauge" doesn't have a valid "TypeConverter", to analyze the character string "/r/n". Line 0 Position 0.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Daniel,

Based on this MSDN article, you would need to include the following namespaces as well:
xmlns='http://schemas.microsoft.com/client/2007' 
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
In addition, in that sample they call ToString() on the XElement, instead of calling CreateReader().

If this doesn't help please put together a small sample project that we can run and email it over to our support address. Once we have that we can take a closer look. Also be sure to remove any executable files from the zip archive, or rename the extension so it's not rejected by our email servers.


Actipro Software Support

Posted 14 years ago by Daniel Koslowski
Avatar
Thanks for you further help!

I added the namespaces in question but still the loading doesn't work as aspected. The provided link to the MSDN article unfortunately leads back to the Actipro Support Forum.

In addition I'm sending a small sample project.

It shows the dynamical loading of a standard WPF Xaml Button which works correctly ... and the error I get by intending to load the gauge.

Daniel
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Daniel,

Sorry, meant to link to an MSDN page, but noticed now that it's for Silverlight. I'm not sure why that code works for the native Button, but not our Gauge controls. If you alter the reader to be:
using (StringReader sr = new StringReader(gauge.ToString())) {
    LinearGauge lg = (LinearGauge)XamlReader.Load(XmlReader.Create(sr));
    this.Panel_Actipro.Children.Add(lg);
}
Then it will properly load the LinearGauge. It appears to be an issue with the underlying reader when using CreateReader(). The error is correct, in that there is no TypeConverter for LinearGauge as it doesn't need one. There may be something baked into .NET that better supports the native WPF controls in this scenario.


Actipro Software Support

Posted 14 years ago by Daniel Koslowski
Avatar
Thanks for your help !!
The alternation of the Reader does the trick ... Everything is working as aspected now.
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.