I have added a usercontrol to my project like this:
Public Sub clickAutoDrillLeft(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
Dim LSliderItem as New TriplexAmpsControl
me.LeftSlider.Items.Add(LSliderItem)
End sub
The "LSliderIn" object is an items control, and the "TriplexAmpsControl" is a usercontrol that has three writeonly properties declared as integers named "AmpsPhaseA", "AmpsPhaseB", and "AmpsPhaseC".
If I instantiate the control at runtime as above, I can immediately assign a value to one of the properties like:
Public Sub clickAutoDrillLeft(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
Dim LSliderItem as New TriplexAmpsControl
me.LeftSlider.Items.Add(LSliderItem)
LSliderItem.AmpsPhaseA = 50
End sub
But only within the sub routine. I don't know how to reference the control values elsewhere in the form, because if I try to call the control by its name from some other sub, the compiler tells me, naturally, that the control is not part of the project because it has not been created yet.
All I have been able to find on the subject concerns the creation of controls in code-behind, but noting on how to connect to user controls instantiated the way I have done it.
(Pre-emptive note: excuse my VB - i'm a C# coder :)
You need to create a module level variable:
then in your code somewhere:
Or if that approach is out of the question for some reason then you can give the dynamically created control a name and later in your code use the FrameworkElement.FindName() method (most UI controls will be derived from FrameworkElement). Or you can code up your own little search function like this (excuse the C# syntax, it shouldn't be a problem for you to translate it to VB):