Hi,
I have created the following UserControl (simplified to the bare minimum for clarity):
<UserControl x:Class="StealthComboBox">
I would like the users of my UserControl to be able to add items to the ComboBox through code.
I have tried a few things already by adding code to the StealthComboBox class, here are 2 examples:
Public Items as ItemCollection = cboBox.Items
Public DropDownList as ComboBox = cboBox
Is there a simple way to directly expose the ".Items" and ".SelectedItem" properties and methods in a UserControl? I know that I can create home-made functions in my "StealthComboBox" class that will query the ComboBox values or use its .Items.Add function, like this:
Public Function Add(obj_ as Object) as Integer
Public Function SelectedItem() as Object
This works pretty well, actually. But I'm mostly wondering if there's a more conventional way - one that would give my UserControl the full interface of a ComboBox instead of me "handpicking" the ones I think I will need?
And a more advanced question: what if I want a UserControl with 2 ComboBox items that must be exposed to the user? Isn't there a way to create some kind of "UserControl.List1" and "UserControl.List2", where each of them acts on a separate ComboBox list? (i.e. UserControl.List1.Items.Add and UserControl.List2.Items.Add)
Thanks for the help!
I have created the following UserControl (simplified to the bare minimum for clarity):
<UserControl x:Class="StealthComboBox">
<Grid>
</UserControl><Label Name="lblHeader" />
<Label Name="lblcboBoxValue" />
<ComboBox Name="cboBox" />
</Grid><Label Name="lblcboBoxValue" />
<ComboBox Name="cboBox" />
I would like the users of my UserControl to be able to add items to the ComboBox through code.
I have tried a few things already by adding code to the StealthComboBox class, here are 2 examples:
Public Items as ItemCollection = cboBox.Items
Even though the UserControl builds fine, trying to add it to a project gives me the error "Could not create an instance of type:StealthComboBox"
Public DropDownList as ComboBox = cboBox
The UserControl builds fine and I could add it to my project - it displays fine and Intellisense shows the ComboBox properties fine. However the "DropDownList" item is actually "Nothing": it does not reference to the cboBox inside my UserControl and any attempt to use it gives an NullReferenceException.
Is there a simple way to directly expose the ".Items" and ".SelectedItem" properties and methods in a UserControl? I know that I can create home-made functions in my "StealthComboBox" class that will query the ComboBox values or use its .Items.Add function, like this:
Public Function Add(obj_ as Object) as Integer
Return cboBox.Items.Add(_obj)
End FunctionPublic Function SelectedItem() as Object
Return cboBox.SelectedItem()
End FunctionThis works pretty well, actually. But I'm mostly wondering if there's a more conventional way - one that would give my UserControl the full interface of a ComboBox instead of me "handpicking" the ones I think I will need?
And a more advanced question: what if I want a UserControl with 2 ComboBox items that must be exposed to the user? Isn't there a way to create some kind of "UserControl.List1" and "UserControl.List2", where each of them acts on a separate ComboBox list? (i.e. UserControl.List1.Items.Add and UserControl.List2.Items.Add)
Thanks for the help!