[Silverlight getting started series] embed Treeview into the accordion of Toolkit

Source: Internet
Author: User

The Silverlight toolkit provides an accordion control. How can I embed a Treeview into this accordion? As shown in the following figure:

It is actually quite simple:

 <  Usercontrol  X: Class  = "Accordintreeviewtest. mainpage"  
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: d = "Http://schemas.microsoft.com/expression/blend/2008"
Xmlns: MC = "Http://schemas.openxmlformats.org/markup-compatibility/2006"
MC: ignorable = "D"
Xmlns: Controls = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
D: designheight = "300" D: designwidth = "400" Xmlns: Toolkit = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" >

< Grid X: Name = "Layoutroot" Background = "White" >
< Toolkit: accordion Height = "236" Horizontalalignment = "Left" Margin = "44,28, 0, 0" Name = "Accordion1" Verticalalignment = "TOP" Width = "244" >
< Toolkit: accordionitem Header = "Menu 1" >
< Toolkit: accordionitem. contenttemplate >
< Datatemplate >
< Controls: Treeview Margin = "1" Borderthickness = "0" >
< Controls: treeviewitem Header = "Node1" >
< Controls: treeviewitem Header = "Node1.1" />
< Controls: treeviewitem Header = "Node1.2" />
< Controls: treeviewitem Header = "Node1.3" />
</ Controls: treeviewitem >
< Controls: treeviewitem Header = "Node2" >
< Controls: treeviewitem Header = "Node2.1 _ testlonglonglonglonglongnode" />
< Controls: treeviewitem Header = "Node2.2" />
< Controls: treeviewitem Header = "Node2.3" />
</ Controls: treeviewitem >
</ Controls: Treeview >
</ Datatemplate >
</ Toolkit: accordionitem. contenttemplate >
</ Toolkit: accordionitem >
< Toolkit: accordionitem Content = "Ontent2" Header = "Menu 2" > </ Toolkit: accordionitem >
< Toolkit: accordionitem Content = "Ontent3" Header = "Menu 3" > </ Toolkit: accordionitem >
< Toolkit: accordionitem Content = "Ontent4" Header = "Menu 4" > </ Toolkit: accordionitem >
</ Toolkit: accordion >
</ Grid >
</ Usercontrol >

But there is a problem, that is, the Treeview cannot be automatically strentch, the width and length cannot be consistent with the available length width of accordionitem, and cannot be automatically stretched. The next article solves this problem.

Build a prism custom region Adapter

In addition, if you are using prism, you can also write a regionadapter for this control. Please refer to this article and this article.ArticleIf you use MEF instead of unity, make the following changes:

Add system. Windows. Controls. toolkit and system. Windows. Controls. layout. toolkit references.

Add the export attribute:

[Export]
Public ClassAccordionregionadapter: regionadapterbase<Accordion>
{//...
}

Use the import constructor to inject:

[Importingconstructor]
PublicAccordionregionadapter (iregionbehaviorfactory regionbehaviorfactory)
:Base(Regionbehaviorfactory)
{
}

Finally, in bootstrapper:

 Protected     Override  Regionadaptermappings extends eregionadaptermappings ()
{
VaR Mappings = Base . Assumeregionadaptermappings ();

Mappings. registermapping ( Typeof (Accordion ), This . Container. getexportedvalue < Accordionregionadapter > ());
// Unity Method: This. Container. Resolve <accordionregionadapter> ());
Return Mappings;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.