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
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...
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.