(Note: I'm not sure why there are numerous blank lines in the resulting post -- in Preview mode -- as it looks fine in the 'Compose' editor.)
Using XAML, I am able to define a menu item (XamWebMenuItem) within a menu (XamWebMenu) such that the menu item displays a tree (XamWebTree) through the use of a control template. (See the XAML code below. I need to be able to dynamically build the tree at runtime, not at design time, but have been unable to figure out how to programmatically build the menu item tree (in C#) or at least be able to clear and populate the tree at runtime.
If this can be accomplished, can you post some sample code?
<igMenu:XamWebMenuItem x:Name="_menuItemProperties" Header="Property" Width="Auto" HorizontalAlignment="Right">
Hi Tom
I have a little mistake about HierarchicalDataTemplate. This class is part of Infragistics.Silverlight.v10.1.dll assembly.
If you have any troubles, write me which version of controls do you use.
Sorry about this misunderstanding. In our new release 10.2 the SL controls are renamed and prefix XamWebXXX is only XamXXX. So If you use 10.1 or older release, you should continue reference the control as XamWebXXX, but keep in mind that names of controls are changed.
About your second point, the HierarchicalDataTemplate is part of XamWebTree (XamTree in 10.2) assembly and in this sample, it is used only for demonstration. It is not necessary to use it to populate your tree. From this link http://help.infragistics.com/NetAdvantage/Silverlight/2010.2/CLR4.0/?page=SL_xamTree_Binding_to_Data.html you can read more about how to bind your data to tree.
Regards
Todor
---Update--
Thanks, Todor, for the suggestion and sample code. I am trying to work with the sample code and:
1) I noticed that the sample code seems to be for WPF, not SL (XamMenu vs. XamWebMenu, etc.). This shouldn't be a problem as I'm converting the XamXXX references to XamWebXXX.
2) I can't seem to resolve HierarchicalDataTemplate. Can you tell me which SL assembly the HierarchicalDataTemplate type is in? It's apparently not in the XamWebTree or XamWebMenu dlls.
Thanks,
Tom
2) I can't seem to resolve HierarchicalDataTemplate. Can you tell me which SL assembly the HierarchicalDataTemplate type is in? It's apparently not in the XamWebMenu dll.
Hi TomKent
One good solution I can think is to inherit XanMenuItem, add TreeItemsSource dependency property to it, and bind this property in control template of XamMenuItem. Below is a code sample how to do it.
1. Inherit from XamMenuItem, and declare your property
public class XamMenuItemEx : XamMenuItem
{
#region TreeItemsSource
/// <summary>
/// Identifies the <see cref="TreeItemsSource"/> dependency property.
/// </summary>
public static readonly DependencyProperty TreeItemsSourceProperty = DependencyProperty.Register("TreeItemsSource", typeof(IEnumerable), typeof(XamMenuItemEx), null);
public IEnumerable TreeItemsSource
get { return (IEnumerable)this.GetValue(TreeItemsSourceProperty); }
set { this.SetValue(TreeItemsSourceProperty, value); }
}
#endregion // TreeItemsSource
2. In control template bind XamTree.ItemsSource to above declared property
<ig:XamMenu Grid.Row="1" Grid.Column="1" ExpandOnHover="False">
<ig:XamMenuItem x:Name="_menuItemProperties" Header="Property" Width="Auto" HorizontalAlignment="Right">
<local:XamMenuItemEx Height="Auto" StaysOpenOnClick="True" >
<local:XamMenuItemEx.Template>
<ControlTemplate TargetType="local:XamMenuItemEx">
<ig:XamTree x:Name="tree" ItemsSource="{TemplateBinding TreeItemsSource}">
<ig:XamTree.HierarchicalItemTemplate>
<ig:HierarchicalDataTemplate ItemsSource="{Binding Children}"/>
</ig:XamTree.HierarchicalItemTemplate>
</ig:XamTree>
</ControlTemplate>
</local:XamMenuItemEx.Template>
</local:XamMenuItemEx>
</ig:XamMenuItem>
By this way you can control the items in tree by this TreeItemsSource property.
3. So when you want to change the data displayed in tree you just change data set to TreeItemsSource property
XamMenuItemEx item;
private void ChangedData()
List<Data> data = new List<Data>();
item.TreeItemsSource = data;
If you want to get reference to the tree you can do that in OnApplyTemplate method of XamMenuItemEx class
XamTree tree
public override void OnApplyTemplate()
tree = GetTemplateChild("tree") as XamTree;
Hope this helps