I have created a ControlTemplate that will place a xamComboEditor into the header of an Expander, so it looks like this:
When opened it looks like this:
The idea is that the xamComboEditor will store the names of several presets so changing the value in the dropdown will easily change the values selected in the expander. When closed the user can still easily see the name of the preset values chosen.
As you can see, I have the control template created, but I'm lost trying to figure out how to get access to the properties of the xamComboEditor. For instance, I want to change the values in the dropdown programatically (in VB). I'm relatively new to WPF and I'm sure I'm just missing some concept.
Ideas anyone?
Thanks in advance,
John
I did one sample application to check whether LoadContent() method creates a new instance or gives that object only. I was wondering its not like u said, it gives me that object only and not its new instance.
I could be mistaken but I think you'll find that that doesn't work. A FrameworkTemplate is just that - a template for creating one or more instances of an element. The LoadContent method of FrameworkTemplate uses the visual tree (essentially a FrameworkElementFactory) to create a new instance of the element. So while that method will give you an instance of the element it will not be the instance of the element that is used within the ContentPresenter within the Expander's template. Even if it did you would have to worry that if the theme changed (or more specifically the template of the expander changed) then a new contentpresenter for the header would be created and therefore a new instance of the FrameworkTemplate would be used.
Define HeaderTemplate of Expander for XamComboEditor.
Code in XAML is as follows:-
<Expander.HeaderTemplate>
<DataTemplate>
<infra:XamComboEditor DisplayMemberPath="Name" ValuePath="ID" Name="uxTesting" ItemsSource="{DynamicResource lstCollection}" Width="Auto" ></infra:XamComboEditor>
</DataTemplate>
</Expander.HeaderTemplate>
You can easily access this XamComboEditor in code behind as
XamComboEditor cmbEditor = uxExpander.HeaderTemplate.LoadContent() as XamComboEditor;
Now u get XamComboEditor, you can set any property of it.
I hope this will help you.
Thanks...
If the xamComboEditor is in the ControlTemplate of the Expander then you'd have to use something like FindName to locate the xamComboEditor within the control. A more robust way would be to derive from Expander, override OnApplyTemplate and use GetTemplateChild to access the xamComboEditor. Other options would be to create your own attached properties that you set on the Expander and bind to those properties within your Expander template. Another option would be to not put the xamComboEditor in the ControlTemplate of the Expander - instead set the Header of the Expander to a panel that contains the caption and xamComboEditor and in that way you have access to the comboeditor within the xaml that you define the Expander.