-
Oct 2nd, 2010, 07:18 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Count the Number of Controls on a WPF Form
Hi again,
I'm looking to count the number of controls on a form within WPF. As usual, I have a working winforms example and I'm trying to get its WPF equivalent.
Here's the winforms code based on looking for a chart control:
Code:
Dim countnumberofcharts As Integer = 0
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is System.Windows.Forms.DataVisualization.Charting.Chart Then
countnumberofcharts = countnumberofcharts + 1
End If
Next
And I'm erroring out with "Controls is not a member of MyApp.ControlCountTest"
Thanks to all who have been assisting in my uphill battle of transitioning from winforms to WPF - its definitely an adventure.
Also, as a postscript, is there any known native charting controls for WPF or am I stuck trying to pull in the winforms charts within a wpf window?
-
Oct 2nd, 2010, 07:37 AM
#2
Thread Starter
Hyperactive Member
Re: Count the Number of Controls on a WPF Form
okay so i changed my code to the following:
Code:
Dim countnumberofcharts As Integer = 0
For Each ctrl As Control In Me.grid1.Children
If TypeOf ctrl Is Chart Then
countnumberofcharts = countnumberofcharts + 1
End If
Next
and specifying grid1.children seemed to help the for next loop itsef, but now its erroring out with the following:
"expression of type system.windows.controls.control can never be of type system.windows.forms.datavisualization.charting.chart"
I have all of the imports statements in place for the class - i'll keep digging as usual but if anybody has encountered trying to identify a chart as a control in wpf, i'm all ears.
Thanks.
-
Oct 4th, 2010, 12:15 PM
#3
Lively Member
Re: Count the Number of Controls on a WPF Form
you can always just count by using the index. so like this:
Code:
For i as int32 = 0 to grid1.children.count - 1
if grid1.children.item(i).gettype = gettype(Chart) then
count = count + 1
End If
next i
-
Oct 6th, 2010, 09:11 AM
#4
Thread Starter
Hyperactive Member
Re: Count the Number of Controls on a WPF Form
absolutely bang on - worked like a charm - thx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|