07-24-2018 08:20 PM
Greetings from Michigan,
In my application, I'm placing a meter control onto the second tab of a tab control. The application appears to build fine, but when I run it, it throws a "XamlParseException" exception. The exception appears to only occur with the Meter, Gauge, and Tank controls. All standard VS controls work fine. Again, it only appears when I place the control within the tab control (second tab). I have tried all of the simple/easy things that I know of, rebuild, Clean, restart VS, restart machine, etc. I am uploading the entire solution in a zip file to Mediafire, so if anyone can help me out, I would be very grateful. I require to place a meter control within the groupbox on the second tab of the tab control. See images and solution file. I'm new to XAML and WPF and this is my first WPF application.
Thank you
07-25-2018 10:44 AM
Hi Mmaker,
What version of Visual Studio and Measurement Studio are you using? Also, what operating system are you using as well?
When I ran your code, I got the following error:
If you try and make a new application, and add one of the controls you listed (just the control, no extra logic) does the same behavior occur?
07-25-2018 10:52 AM
It looks like you have run into the same issue as this question. There is already a task to fix this in the next version of Measurement Studio, but until then you can work around the problem by inheriting from the gauge class and returning this custom enumerator to avoid the faulty reset logic:
Class ResetableEnumeratorWrapper Implements IEnumerator Private ReadOnly getEnumerator As Func(Of IEnumerator) Private enumeratorValue As IEnumerator Public Sub New(getEnumerator As Func(Of IEnumerator)) MyClass.getEnumerator = getEnumerator End Sub Private ReadOnly Property Enumerator As IEnumerator Get If (enumeratorValue Is Nothing) Then enumeratorValue = getEnumerator() End If Return enumeratorValue End Get End Property Public ReadOnly Property Current As Object Implements IEnumerator.Current Get Return Enumerator.Current End Get End Property Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext Return Enumerator.MoveNext End Function Public Sub Reset() Implements IEnumerator.Reset Dim oldEnumeratorValue = TryCast(enumeratorValue, IDisposable) Using (oldEnumeratorValue) enumeratorValue = Nothing End Using End Sub End Class Class MyGaugeDouble Inherits GaugeDouble Protected Overrides ReadOnly Property LogicalChildren As IEnumerator Get Return New ResetableEnumeratorWrapper( Function() Return MyBase.LogicalChildren End Function) End Get End Property End Class
In MainWindow.xaml
, simply replace ni:GaugeDouble
with local:MyGaugeDouble
to enable the workaround.
07-25-2018 11:27 AM - edited 07-25-2018 11:28 AM
Thank you for your reply. My OS is Windows 10. Visual Studio 2012 Pro with Measurement Studio 2015 Enterprise. Yes, as you describe, yesterday I tried creating a separate application with a tab control and two tabs and then adding the MS controls in question. It compiled and ran fine. In my "problem" application, there is not any business logic code other than declaring some variables and maybe a Class or two as I haven't done much with the code and I'm just doing the UI design right now. I'm creating the UI in Blend, and not writing any XAML code manually. So, I don't understand what the problem could be from my actual work application to the "test" application where the controls were fine on (??), hence asking some that are smarter than me. 🙂 .
Were you able to open the application in design view or is that just the exception that was thrown when you tried running the code? Paul posted a possible work around to my problem, but when is a new version of Measurement Studio scheduled to be released that fixes this issue?
Thanks,
Don
07-25-2018 02:05 PM
Paul,
Thank you, looks like that worked and fixed the problem! However....apparently Blend 2012 doesn't like it and now I can't view the application XAML in Design View (Blend 2012). This may be an inconvenience more than a problem or deal breaker. In Blend 2017, its fine and I can view it there. But I've had issues with attempting to view and make changes to the UI design in Blend 2017 because it doesn't have Measurement Studio installed/licensed to it. So every so often, a control will just disappear off the design in Blend 2017 and throw an exception error until I delete the control completely off the design. Blend is where I'm doing all of the design work, as I prefer that to writing XAML code.
I certainly appreciate the help going forward so I thank you and the Measurement Studio team for that. I must say though that I'm a bit dismayed as to why these WPF controls don't work right out of the box like they should and there is required all this work around code on the developer's end to make it work (?). It appears I'm going to have to implement the same code for the Tank and Meter controls and any other control with the same issues (Chart, graph?). Thank you.
07-25-2018 02:58 PM
Yes, I am afraid most of the Measurement Studio controls have this issue in the currently. It only occurs for more complex layouts when WPF conducts repeated element name searches, which is why it was not caught before release.
I have Blend 2012 on the test machine, but I could not reproduce the error you are seeing: after running the project in Visual Studio, all tabs also displayed correctly in Blend. Assuming a rebuild does not fix the issue, perhaps moving the gauge into a user control would avoid the Blend issue?
07-09-2019 11:10 AM
Just wanted to let you know this issue was fixed in the Measurement Studio 2019 release.