KirilStanoev Silverlight 2.0 controls http://blogs.telerik.com/KirilStanoev/Posts.aspx http://backend.userland.com/rss RadBook now supports virtualization <p>I am proud to announce that <strong>RadBook</strong>, along with <strong>RadGridView</strong>, <strong>RadTreeView</strong>, <strong>RadTreeListView</strong>, <strong>RadChart </strong>and <strong>RadScheduler</strong>, now supports virtualization. With previous versions, it would take up to <strong>16 seconds </strong>to load <strong>1000 pages</strong>, where now it takes just <strong>2 seconds</strong> to load a set of <strong>10,000,000 (<em>10 million</em>)</strong> items. </p> <p>&nbsp;<img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/img01.sflb" /></p> <p></p> <p> The cause of the performance boost is the way RadBook handles the unnecessary(non-visible) elements. As you probably know, while turning a page, only four pages are visible at any given moment in time. </p> <p><img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/img02.sflb" /> </p> <p>Previous versions of RadBook would just collapse the unnecessary elements, which had a significant impact on the initial loading time. The new version of RadBook now takes advantage of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingpanel.aspx">VirutalizingPanel</a> and creates only as many elements as necessary for the book to render properly. Enjoy and if you have comments or questions on the topic, let us know.</p> http://blogs.telerik.com/KirilStanoev/Posts/10-03-12/radbook_now_supports_virtualization.aspx Kiril Stanoev http://blogs.telerik.com/KirilStanoev/Posts/10-03-12/radbook_now_supports_virtualization.aspx f81aa3cb-b214-4c49-aa58-001f96c1064e Fri, 12 Mar 2010 03:58:00 GMT First Look at RadBook for Silverlight <p>I am glad to announce the addition of one more control to our Silverlight suite. The control is called <a href="http://www.telerik.com/products/silverlight/book.aspx">RadBook </a>and it is a <a href="http://en.wikipedia.org/wiki/Flip_page">page-flip type of control</a> that allows browsing through a set of items as if flipping the pages of a book.</p> <p><img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/bookScreenshot.sflb" /> </p> <p>RadBook inherits <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol(VS.95).aspx">System.Windows.Controls.ItemsControl</a>, which allows you to turn any type of content into a&nbsp;RadBook's page. The main features of RadBook are:</p> <ul> <li>Ability to template every page by using <a href="http://www.telerik.com/help/silverlight/radbook-data-templates.html">LeftPageTemplate</a>, <a href="http://www.telerik.com/help/silverlight/radbook-data-templates.html">RightPageTemplate</a>, LeftPageTemplateSelector and RightPageTemplateSelector. </li> <li>Ability to change the way a page is flipped i.e. <a href="http://www.telerik.com/help/silverlight/radbook-page-flip-mode.html">flip a page on a single click, double click</a> or simply forbid page flipping. </li> <li>Ability to define <a href="http://www.telerik.com/help/silverlight/radbook-show-first-page-on-the-right.html">whether the first page will appear on the left or on the right</a>, thus resembling a real cover page. </li> <li>Smooth flip animations that significantly improve the user experience. </li> </ul> <p>&nbsp;</p> <p>Since this is RadBook's first version, I'd like to ask for any feedback you might have. It would be highly appreciated. Also, if you want to learn more about RadBook, you can take a look at our <a href="http://demos.telerik.com/silverlight/#Book/FirstLook">online demos</a> or <a href="http://www.telerik.com/community.aspx">join our community</a>. </p> http://blogs.telerik.com/KirilStanoev/Posts/09-11-19/first_look_at_radbook_for_silverlight.aspx Kiril Stanoev http://blogs.telerik.com/KirilStanoev/Posts/09-11-19/first_look_at_radbook_for_silverlight.aspx 91ba38c7-9b2f-4a39-a308-a4de3d752286 Thu, 19 Nov 2009 10:56:00 GMT Editing Telerik's Silverlight Controls in Expression Blend   <p>Along with the release of Telerik RadControls for Silverlight Beta 2, we also released a "blendable" Silverlight project. What I mean under "blendable" is that when this project is opened in Expression Blend, it allows you an easy and straightforward approach to editing the style of every control in out suite.</p> <p>To begin with, go to your <a href="http://www.telerik.com/client.net/login-pages/client.net-login/b30t-t.aspx">Client.net account and download Telerik.Windows.Controls.Blend</a>.</p> <p>Unzip the project anywhere and open the Telerik.Windows.Controls.Blend.sln files using Expression Blend.</p> <p><img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/blog040908_01.sflb" /> </p> <p>If you explore the Project tab, you will find that each control is represented by a separate XAML file.</p> <p><img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/blog040908_02.sflb" /> </p> <p>Open, for example, the Expander.xaml file. You will see that there is nothing more than an Expander control on the page. If you want to edit the ControlTemplate of the control, simply right-click the control and choose <strong>"Edit Control Parts(Template) &gt; Edit Template"</strong></p> <p><img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/blog040908_03.sflb" /> </p> <p>After that Blend will show you all the elements that compose the ControlTemplate of the Expander control.</p> <p><img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/blog040908_04.sflb" /> </p> <p>I am not much of a designer so I will leave the rest to your imagination.</p> <p>The same instructions are fully applicable to the rest of the controls in the project. All the xaml that a single control uses is placed inside the resources of the respective host page. This means that if you want to edit the ControlTemplate of the TreeView you can find its xaml inside the UserControl.Resources tag in TreeView.xaml.</p> <p><img alt="" src="http://blogs.telerik.com/Libraries/Silverlight_team/blog040908_05.sflb" /></p> http://blogs.telerik.com/KirilStanoev/Posts/08-09-04/editing_telerik_s_silverlight_controls_in_expression_blend.aspx Kiril Stanoev http://blogs.telerik.com/KirilStanoev/Posts/08-09-04/editing_telerik_s_silverlight_controls_in_expression_blend.aspx 20a7ae8c-870f-4bfd-ae95-6716872c8451 Thu, 04 Sep 2008 20:00:31 GMT Populating Silverlight TreeView from WCF Service with LINQ to SQL <p>In this example I will show you how to populate a RadTreeView using LINQ and WCF. Also you will see how to transform a flat data into a hierarchical one.</p> <p><strong>The target result is:</strong></p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/Untitled.sflb" /> </p> <p><strong>1.</strong> Create a new <strong>Silverlight Web Application Project</strong></p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/newProject_01.sflb" /> </p> <p><strong>NOTE: Make sure you choose "Web Application Project"</strong></p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/newProject_02.sflb" /> </p> <p>After the project loads you can see that besides the regular Silverlight application, Visual Studio adds a Web application that will host the .xap file.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/examine.sflb" />&nbsp; </p> <p>Before writing any LINQ or creating any WCF service, we need a database to target.</p> <p><strong>2.</strong> Right-click on <strong>RadTreeViewWithWCFWeb</strong> project and add a new item - <strong>"SQL Server Database"</strong>. You can give the database any name you wish. I personally called mine <strong>TVSeries</strong> since this is going to be a TV related tutorial :).</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/newSQLDatabase_01.sflb" /> </p> <p>Visual Studio will ask you whether you want to place the database in the <strong>App_Data</strong> folder. Click Yes to confirm.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/newSQLDatabase_02.sflb" /> </p> <p>Examine the <strong>RadTreeViewWithWCFWeb's App_Data </strong>folder and you will find your database there.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/newSQLDatabase_03.sflb" /> </p> <p><strong>3.</strong> Double-clicking the <strong>TVSeries.mdf</strong> file will automatically send the database to the <strong>"Server Explorer"</strong> window.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/serverExplorer_01.sflb" /> </p> <p>It is now time to populate the database with some data. To keep the tutorial short, I will add only one table and fill it with data. I have called my table <strong>FoxTVSeries</strong>. You can <a href="http://blogs.telerik.com/Libraries/Silverlight_team/TVSeries.sflb?download=true">download the database here</a>.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/database.sflb" /> </p> <p>Since the database is populated, it is time to do <strong>LINQ</strong> on it.</p> <p><strong>4.</strong> Right-click on <strong>RadTreeViewWithWCFWeb</strong> project and add a new item - <strong>"LINQ to SQL Classes"</strong>.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/LINQtoSQLClasses.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/LINQtoSQLClasses_02.sflb" /> </p> <p><strong>5.</strong> Open the <strong>"Server Explorer"</strong> window and drag the <strong>FoxTVSeries</strong> table onto the <strong>"Object Relational Designer"</strong>. (<strong>"Object Relational Designer"</strong> opens automatically when you open the <strong>DataClasses1.dbml</strong> file)</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/LINQtoSQLClasses_03.sflb" /> </p> <p>The "Object Relational Designer" will automatically show the columns that the table has.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/LINQtoSQLClasses_04.sflb" /> </p> <p><strong>6.</strong> By default, the <strong>LINQ</strong> class is not serializable. In order to use the table in a web service, we need to make the <strong>DataClasse1.dbml</strong> file serializable. Right-click on the design surface and choose <strong>Properties</strong> from the drop-down. In the properties window change the <strong>"Serialization Mode"</strong> to <strong>Unidirectional</strong>.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/LINQtoSQLClasses_05.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/LINQtoSQLClasses_06.sflb" />&nbsp;</p> <p><strong>7.</strong> The <strong>LINQ</strong> is done, it is time now to create the web service. Again, right-click on <strong>RadTreeViewWithWCFWeb</strong> project and add a new item - <strong>"WCF Service".</strong></p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/wcfService_01.sflb" /> </p> <p>Visual Studio adds 3 files that hold the service contract for the WCF service - <strong>IService1.cs, Service1.svc</strong> and a code-behind to it - <strong>Service1.svc.cs</strong>.</p> <p><strong>8.</strong> Open the first file - <strong>IService1.cs</strong>. This file contains the operation contract. Change the name and the signature of the <strong>DoWork()</strong> method - change its name to <strong>GetTVSerie</strong> and change its return value to be <strong>List&lt;FoxTVSery&gt;.</strong></p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/wcfService_02.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/wcfService_03.sflb" /> </p> <p><strong>9.</strong> Go to the <strong>Service1.svc.cs</strong> file and implement the <strong>IService1</strong> interface</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/wcfServiceImplement.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/wcfServiceImplement_02.sflb" /> </p> <p><strong>10.</strong> Keeping the example as simple as possible, we will select all the the items in the table, without any grouping, ordering etc.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/wcfServiceImplement_03.sflb" /> </p> <p><strong>11.</strong> One thing that is important is to make sure that your web service uses a <strong>basicHttpBinding</strong>, not the default <strong>wsHttpBinding</strong>. Go to the <strong>Web.config</strong> file and scroll down until you find the <strong>system.serviceModel</strong> tag. Change the <strong>binding="wsHttpBinding"</strong> to <strong>binding="basicHttpBinding".</strong></p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/webconfig.sflb" /> </p> <p>The reason to change the binding is because Silverlight supports only basic binding (SOAP 1.1 etc.). </p> <p>Congrats, the web service is all set! The next step is to use the web service in the Silverlight application.</p> <p><strong>12.</strong> Go to the <strong>RadTreeViewWithWCF</strong> project, right-click on References and add a "Service Reference".</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/reference.sflb" /> </p> <p>A popup window appears hit the Discover button&nbsp; to find the web service and then hit OK to add it.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/reference_02.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/reference_03.sflb" /> </p> <p><strong>13.</strong> Once you have the WCF Service added, it is time work a little on the XAML and actually add the TreeView. First of all add references to <a href="http://blogs.telerik.com/Libraries/Silverlight_team/Telerik.Windows.Controls.sflb?download=true">Telerik.Windows.Controls.dll</a> and <a href="http://blogs.telerik.com/Libraries/Silverlight_team/Telerik.Windows.Controls.Navigation.sflb?download=true">Telerik.Windows.Controls.Navigation.dll</a>.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/reference_04.sflb" /> </p> <p><strong>14.</strong> Open the Page.xaml file and reference the previously added dlls. Also you need to reference the RadTreeViewWithWCF project.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/xamlReference.sflb" /> </p> <p><strong>15.</strong> In the <strong>UserControl.Resources</strong> of <strong>Page.xaml</strong> we have to create a hierarchical data template that will be used as an item template for the TreeView. Also we create the data source for the TreeView</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">UserControl.Resources</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">local:HierarchicalDataSource</span> <span style="color: rgb(255, 0, 0);">x:Key</span><span style="color: rgb(0, 0, 255);">="Source"</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">core:HierarchicalDataTemplate</span> <span style="color: rgb(255, 0, 0);">x:Key</span><span style="color: rgb(0, 0, 255);">="NodeTemplate"</span> <span style="color: rgb(255, 0, 0);">ItemsSource</span><span style="color: rgb(0, 0, 255);">="{Binding Children}"</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">core:HierarchicalDataTemplate.HeaderTemplate</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 7:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">DataTemplate</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">TextBlock</span> <span style="color: rgb(255, 0, 0);">Text</span><span style="color: rgb(0, 0, 255);">="{Binding NodeText}"</span> <span style="color: rgb(255, 0, 0);">TextWrapping</span><span style="color: rgb(0, 0, 255);">="Wrap"</span> <span style="color: rgb(255, 0, 0);">Width</span><span style="color: rgb(0, 0, 255);">="400"</span><span style="color: rgb(0, 0, 255);">/&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 9:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">DataTemplate</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">core:HierarchicalDataTemplate.HeaderTemplate</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 11:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">core:HierarchicalDataTemplate</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 12:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 13:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">UserControl.Resources</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> </div> </div> <p><strong>16.</strong> Next step is to create the TreeView and apply the item template and the data source.</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">telerik:RadTreeView</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> <span style="color: rgb(255, 0, 0);">HorizontalAlignment</span><span style="color: rgb(0, 0, 255);">="Left"</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(255, 0, 0);">VerticalAlignment</span><span style="color: rgb(0, 0, 255);">="Top"</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> <span style="color: rgb(255, 0, 0);">ItemsSource</span><span style="color: rgb(0, 0, 255);">="{Binding Source={StaticResource Source}}"</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(255, 0, 0);">ItemTemplate</span><span style="color: rgb(0, 0, 255);">="{StaticResource NodeTemplate}"</span> </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre> </div> </div> <p>&nbsp;</p> <p><strong>17.</strong> If you decide to build, Visual Studio will encounter an error at the line</p> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">local:HierarchicalDataSource</span> <span style="color: rgb(255, 0, 0);">x:Key</span><span style="color: rgb(0, 0, 255);">="Source"</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre> <p>&nbsp;</p> <p><strong>18.</strong> In the RadTreeViewWithWCF project add a new class called HierarchicalDataSource.cs. Make this class inherit from ObservableCollection&lt;TableItem&gt;.</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> HierarchicalDataSource : ObservableCollection&lt;TableItem&gt;</pre> </div> </div> <p>Try to build and you will get an error telling you that you are missing the TableItem class. Therefore we need to create the TableItem class. This class is going to represent a single entry from the FoxTVSeries table. This means that this class is going to have properties like NodeID, ParentID, NodeText and one additional property called Children. The Children property will be used to turn the flat data into hierarchical one.</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> TableItem</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">string</span> nodeText;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">int</span> nodeID;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">private</span> System.Nullable&lt;<span style="color: rgb(0, 0, 255);">int</span>&gt; parentID;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> <span style="color: rgb(0, 0, 255);">private</span> List&lt;TableItem&gt; children;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 7:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> <span style="color: rgb(0, 0, 255);">public</span> TableItem(<span style="color: rgb(0, 0, 255);">string</span> nodeText, <span style="color: rgb(0, 0, 255);">int</span> nodeID, System.Nullable&lt;<span style="color: rgb(0, 0, 255);">int</span>&gt; parentID)</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 9:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span> <span style="color: rgb(0, 0, 255);">this</span>.nodeText = nodeText;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 11:</span> <span style="color: rgb(0, 0, 255);">this</span>.nodeID = nodeID;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 12:</span> <span style="color: rgb(0, 0, 255);">this</span>.parentID = parentID;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 13:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 14:</span> <span style="color: rgb(0, 0, 255);">this</span>.children = <span style="color: rgb(0, 0, 255);">new</span> List&lt;TableItem&gt;();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 15:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 16:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 17:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">string</span> NodeText</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 18:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 19:</span> get</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 20:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 21:</span> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">this</span>.nodeText;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 22:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 23:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 24:</span> <span style="color: rgb(0, 0, 255);">public</span> System.Nullable&lt;<span style="color: rgb(0, 0, 255);">int</span>&gt; ParentID</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 25:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 26:</span> get</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 27:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 28:</span> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">this</span>.parentID;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 29:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 30:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 31:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">int</span> NodeID</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 32:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 33:</span> get</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 34:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 35:</span> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">this</span>.nodeID;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 36:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 37:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 38:</span> <span style="color: rgb(0, 0, 255);">public</span> List&lt;TableItem&gt; Children</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 39:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 40:</span> get</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 41:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 42:</span> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">this</span>.children;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 43:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 44:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 45:</span> }</pre> </div> </div> <p>Once the TableItem class is done, we are ready to proceed with the HierarchicalDataSource class.</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; height: 234px; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> HierarchicalDataSource : ObservableCollection&lt;TableItem&gt;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 128, 0);">// This list holds all the items that come from the web service result</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> <span style="color: rgb(0, 0, 255);">private</span> List&lt;TableItem&gt; unsortedList = <span style="color: rgb(0, 0, 255);">new</span> List&lt;TableItem&gt;();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> <span style="color: rgb(0, 0, 255);">public</span> HierarchicalDataSource()</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 7:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> <span style="color: rgb(0, 128, 0);">// Create a new instance of the web service and get the data from the table</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 9:</span> Service1Client webService = <span style="color: rgb(0, 0, 255);">new</span> Service1Client();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span> webService.GetTVSerieCompleted += <span style="color: rgb(0, 0, 255);">new</span> EventHandler&lt;GetTVSerieCompletedEventArgs&gt;(WebService_GetTableCompleted);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 11:</span> webService.GetTVSerieAsync();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 12:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 13:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 14:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> WebService_GetTableCompleted(<span style="color: rgb(0, 0, 255);">object</span> sender, GetTVSerieCompletedEventArgs e)</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 15:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 16:</span> <span style="color: rgb(0, 128, 0);">// transfer all the items from the result to the unsorted list</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 17:</span> <span style="color: rgb(0, 0, 255);">foreach</span> (FoxTVSery item <span style="color: rgb(0, 0, 255);">in</span> e.Result)</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 18:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 19:</span> TableItem genericItem = <span style="color: rgb(0, 0, 255);">new</span> TableItem(item.NodeText, item.NodeID, item.ParentID);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 20:</span> <span style="color: rgb(0, 0, 255);">this</span>.unsortedList.Add(genericItem);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 21:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 22:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 23:</span> <span style="color: rgb(0, 128, 0);">// Get all the first level nodes. In our case it is only one - House M.D.</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 24:</span> var rootNodes = <span style="color: rgb(0, 0, 255);">this</span>.unsortedList.Where(x =&gt; x.ParentID == x.NodeID);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 25:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 26:</span> <span style="color: rgb(0, 128, 0);">// Foreach root node, get all its children and add the node to the HierarchicalDataSource.</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 27:</span> <span style="color: rgb(0, 128, 0);">// see bellow how the FindChildren method works</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 28:</span> <span style="color: rgb(0, 0, 255);">foreach</span> (TableItem node <span style="color: rgb(0, 0, 255);">in</span> rootNodes)</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 29:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 30:</span> <span style="color: rgb(0, 0, 255);">this</span>.FindChildren(node);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 31:</span> <span style="color: rgb(0, 0, 255);">this</span>.Add(node);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 32:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 33:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 34:</span> </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 35:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> FindChildren(TableItem item)</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 36:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 37:</span> <span style="color: rgb(0, 128, 0);">// find all the children of the item</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 38:</span> var children = unsortedList.Where(x =&gt; x.ParentID == item.NodeID &amp;&amp; x.NodeID != item.NodeID);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 39:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 40:</span> <span style="color: rgb(0, 128, 0);">// add the child to the item's children collection and call the FindChildren recursively, in case the child has children</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 41:</span> <span style="color: rgb(0, 0, 255);">foreach</span> (TableItem child <span style="color: rgb(0, 0, 255);">in</span> children)</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 42:</span> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 43:</span> item.Children.Add(child);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 44:</span> FindChildren(child);</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 45:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 46:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 47:</span> }</pre> </div> </div> <p>It is a pretty straightforward class. It has a list that will contain the flat data coming from the web service result. Then this list is traversed and the hierarchical data is built.</p> <p>If you need any more explanations or you have any suggestions, do not hesitate to drop me a comment.</p> <p>Resources:</p> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/RadTreeViewWithWCF.sflb?download=true">RadTreeViewWithWCF.zip</a></p> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/Telerik.Windows.Controls.sflb?download=true">Telerik.Windows.Controls.dll</a></p> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/Telerik.Windows.Controls.Navigation.sflb?download=true">Telerik.Windows.Controls.Navigation.dll</a></p> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/TVSeries.sflb?download=true">FoxTVSeries.mdf</a></p> http://blogs.telerik.com/KirilStanoev/Posts/08-08-27/populating_silverlight_treeview_from_wcf_service_with_linq_to_sql.aspx Kiril Stanoev http://blogs.telerik.com/KirilStanoev/Posts/08-08-27/populating_silverlight_treeview_from_wcf_service_with_linq_to_sql.aspx cdffbd97-eb06-407b-89de-04a5d51545f7 Wed, 27 Aug 2008 06:20:00 GMT Editing Slider's ControlTemplate in Expression Blend <p>In this tutorial I will show you how to edit the ControlTemplate of one of our controls – <a href="http://www.telerik.com/demos/silverlight/#Examples/Slider/FirstLook">the slider</a>. Before you begin you need to cover the prerequisites bellow. You have to download the Telerik Controls for Silverlight as well as the project that contains all the controls and their ControlTemplates. </p> <p><a href="http://www.telerik.com/products/silverlight/overview.aspx">Telerik Controls for Silverlight</a> </p> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/Telerik_Windows_Controls_Blend.sflb">Project with all the ControlTemplates</a> – this project is created in such way that allows you easily to edit the control templates. This means that all the control templates are copied in the resources of each Silverlight page. </p> <p>If you are missing any of the components bellow, please install them: </p> <p><a href="http://msdn.microsoft.com/en-us/vs2008/products/cc268305.aspx">Visual Studio 2008</a></p> <p><a href="http://go.microsoft.com/fwlink/?LinkId=120319">Silverlight 2 Beta 2</a></p> <p><a href="http://expression.microsoft.com/en-us/cc643423.aspx">Blend 2.5 June 2008 Preview</a></p> <p>&nbsp;</p> <p>The first few steps from this tutorial can be done directly in Expression Blend, but for ease I will use Visual Studio and take advantage of its Intellisense. </p> <p><strong><span style="font-size: 18px;">1.</span></strong> Create a new Silverlight project in Visual Studio and call it StylingSlider. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/01.sflb" /></p> <p>&nbsp; </p> <p>Note: In this particular project the test page is generated dynamically, but you are free to attach a website. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/02.sflb" /> </p> <p><strong><span style="font-size: 18px;">2.</span></strong> Once the project is loaded, add a reference to the Telerik.Windows.Controls.dll </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/03.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/04.sflb" /> </p> <p><strong><span style="font-size: 18px;">3.</span></strong> Open Page.xaml and add an xmlns referencing the previously added dll.</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; height: 37px; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"</pre> </div> </div> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/05.sflb" /> </p> <p>Build the project and you are ready to open Page.xaml in Expression Blend. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/06.sflb" /> </p> <p><strong><span style="font-size: 18px;">4.</span></strong> When Blend loads, click the “Asset Library” button, choose the “Custom Controls” tab and then select RadSlider from the list. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/07.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/08.sflb" /> </p> <p><strong><span style="font-size: 18px;">5.</span></strong> Add RadSlider to the page (can be done in two ways): </p> <blockquote> <p><span style="font-size: 18px;"><strong>5.1</strong></span> Double-click the icon to insert RadSlider</p> </blockquote> <blockquote> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/09.sflb" /> </p> </blockquote> <blockquote> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/10.sflb" /> </p> </blockquote> <blockquote> <p><strong><span style="font-size: 18px;">5.2</span></strong> Switch to XAML view and add RadSlider declaratively.</p> </blockquote> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="LayoutRoot"</span> <span style="color: rgb(255, 0, 0);">Background</span><span style="color: rgb(0, 0, 255);">="White"</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">telerik:RadSlider</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> </div> </div> <p>Currently Blend is not able to find the ControlTemplate of the control, so if you decide to right click and select “Edit Control Parts (Template)” &gt; “Edit a Copy”, you will get a ControlTemplate with nothing inside. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/11.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/12.sflb" /> </p> <p>Therefore you need to manually insert the theme in the resources of the page. </p> <p><strong><span style="font-size: 18px;">6.</span></strong> From the zip archive, open Slider.xaml, copy everything that is inside the UserControl.Resources and paste it in the Resources of your UserControl. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/13.sflb" /> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/14.sflb" /> </p> <p><strong><span style="font-size: 18px;">7.</span></strong> RadSlider’s ControlTemplate uses the Visual State Manager, therefore you need to add a reference to the System.Windows.dll in order to use it.</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"</pre> </div> </div> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/15.sflb" /> </p> <p>We are approaching the finish line. Now you need to apply the style that you added in the resources to the slider. </p> <p><strong><span style="font-size: 18px;">8.</span></strong> Expand the style that targets RadSlider and add a key to it as shown in the screen shot bellow. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/16.sflb" /> </p> <p><strong><span style="font-size: 18px;">9.</span></strong> Apply the style to the slider, again can be done in two ways. </p> <blockquote> <p><strong><span style="font-size: 18px;">9.1</span></strong> Apply the style using Blend</p> </blockquote> <blockquote> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/17.sflb" /> </p> </blockquote> <blockquote> <p><strong><span style="font-size: 18px;">9.2</span></strong> Declaratively</p> </blockquote> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid</span> <span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="LayoutRoot"</span> <span style="color: rgb(255, 0, 0);">Background</span><span style="color: rgb(0, 0, 255);">="White"</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">telerik:RadSlider</span> <span style="color: rgb(255, 0, 0);">Style</span><span style="color: rgb(0, 0, 255);">="{StaticResource SliderStyle}"</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre> </div> </div> <p><strong><span style="font-size: 18px;">10.</span></strong> With all the steps completed so far, you can easily edit the template of the slider. </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/19.sflb" />&nbsp;&nbsp; </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/20.sflb" /> </p> <p>&nbsp; </p> <p>Source code for this tutorial: <a href="http://blogs.telerik.com/Libraries/Silverlight_team/StylingSlider.sflb?download=true">StylingSlider</a> </p> <p>Additional Resources: </p> <p><a href="http://blogs.msdn.com/expression/archive/2008/07/11/more-articles-on-visual-state-manager.aspx">Articles on Visual State Manager</a> </p> <p><a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx">Using ControlTemplates</a> </p> <p>&nbsp; </p> <p>Any comments and suggestions would be greatly appreciated. </p> http://blogs.telerik.com/KirilStanoev/Posts/08-08-22/editing_slider_s_controltemplate_in_expression_blend.aspx Kiril Stanoev http://blogs.telerik.com/KirilStanoev/Posts/08-08-22/editing_slider_s_controltemplate_in_expression_blend.aspx 6f4ee043-fc6d-4a84-a560-4604d6dd409d Fri, 22 Aug 2008 08:37:22 GMT How To: Color Picker done with few slider controls <p>This tutorial demonstrates how to create a color picker using nothing more than few elements and Telerik's slider control for Silverlight. <br /> To start off, create a new Silverlight project. It is up to you to decide whether you want a web page in the project or not. This particular example does not to include a web page, but a simple html page that is generated dynamically. Once you have the project created go ahead and add a reference to the Telerik.Windows.Controls.dll. At the top of your main UserControl, add a namespace in order to use the dll. Check if everything compiles and we are done with the preparation.</p> <p>On the image bellow you can see what the basic structure of the color picker will be. </p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-HowToColorPickerdonewithfewslidercontrol_EB84-initial_skeleton_2.sflb"><img height="327" border="0" width="435" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-HowToColorPickerdonewithfewslidercontrol_EB84-initial_skeleton_thumb.sflb" alt="Basic structure" style="border-width: 0px;" /></a> </p> <p>As you can see there are 3 sliders (hue, saturation and luminance), 1 thumb to pick the color, 1 element to display the result(can be anything that you wish, but in this particular example it is a Rectangle) and a Pad(a Grid that contains the thumb). <br /> You might have already guessed but we are going to use the HSL(hue,saturation,luminance) to RGB(red,green,blue) conversion. Since this is not a tutorial on how the conversion exactly works I advice you to search for HSL/HSV to RGB in case you want to understand the details.</p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-HowToColorPickerdonewithfewslidercontrol_EB84-blend_structure_2.sflb"><img height="379" border="0" width="731" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-HowToColorPickerdonewithfewslidercontrol_EB84-blend_structure_thumb.sflb" alt="Blend" style="border-width: 0px;" /></a> </p> <p>This is the structure of the elements in Blend. Most of the elements have already been explained. One key part that needs some explanation is the resizer element. </p> <p><a href="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-HowToColorPickerdonewithfewslidercontrol_EB84-pad_2.sflb"><img height="278" border="0" width="277" src="http://blogs.telerik.com/Libraries/MetaBlog/WindowsLiveWriter-HowToColorPickerdonewithfewslidercontrol_EB84-pad_thumb.sflb" alt="pad" style="border-width: 0px;" /></a> </p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/resizer_close.sflb" /> </p> <p>The resizer is necessary in order to be able to move the color picker thumb. Basically, moving the color picker thumb causes the saturation and luminance sliders to update their values. These values are set as width and height respectively to the resizer. Changing resizer's size will force the container grid(pad) to recalculate the size of its row and columns and thus causing the thumb to move. Simple enough!</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> LuminanceSlider_ValueChanged(<span style="color: rgb(0, 0, 255);">object</span> sender, RoutedPropertyChangedEventArgs&lt;<span style="color: rgb(0, 0, 255);">double</span>&gt; e) </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> { </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> resizer.Height = DistanceConverter.ValueToPixels((<span style="color: rgb(0, 0, 255);">double</span>)e.NewValue, (pad.ActualHeight - colorPickerThumb.ActualHeight), (luminanceSlider.Maximum - luminanceSlider.Minimum)); </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> SaturationSlider_ValueChanged(<span style="color: rgb(0, 0, 255);">object</span> sender, RoutedPropertyChangedEventArgs&lt;<span style="color: rgb(0, 0, 255);">double</span>&gt; e) </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 7:</span> { </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> resizer.Width = DistanceConverter.ValueToPixels((<span style="color: rgb(0, 0, 255);">double</span>)e.NewValue, (pad.ActualWidth - colorPickerThumb.ActualWidth), (saturationSlider.Maximum - saturationSlider.Minimum)); </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 9:</span> }</pre> </div> </div> <p><strong>Note:</strong> The ValueToPixels method accepts 3 arguments - the current value of the slider, the size in pixels of the container that holds the color picker thumb, the range of the slider(Range == Maximum - Minimum)</p> <p>Change the value of the slider's and see how this reflects the thumb</p> <object height="300" width="300" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAIAAACHwAAAh8AAAAAAAAAAAAAAAAAAGAAAAAvAEwAaQBiAHIAYQByAGkAZQBzAC8AUwBpAGwAdgBlAHIAbABpAGcAaAB0ACAAdABlAGEAbQAvAEMAbwBsAG8AcgBQAGkAYwBrAGUAcgBfADAAMQAuAHMAZgBsAGIAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" type="application/x-silverlight-2-b2"> <param name="source" value="/Libraries/Silverlight_team/ColorPicker_01.sflb"> <a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none;"> </a></object> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/ColorPicker_01_1.sflb">Download source</a></p> <p>On the sample above, if you try to move the thumb nothing will happen. This is in fact the next step - making the thumb dragable. <br /> Thumb control has 2 major events - DragStarted and DragDelta. Our goal is: <br /> 1. On DragStarted to obtain the value of saturation and luminance slider's. <br /> 2. On DragDelta to calculate the offset(horizontal and vertical) and convert it from pixels to value . <br /> 3. Assign the converted values to saturation and luminance sliders. <br /> 4. Optional: Make saturation and luminance sliders invisible</p> <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 1:</span> <span style="color: rgb(0, 128, 0);">// ColorPicker Thumb Drag events </span></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 2:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> ColorPickerThumb_DragStarted(<span style="color: rgb(0, 0, 255);">object</span> sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 3:</span> { </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 4:</span> <span style="color: rgb(0, 0, 255);">this</span>.dragDeltaX = saturationSlider.Value; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 5:</span> <span style="color: rgb(0, 0, 255);">this</span>.dragDeltaY = luminanceSlider.Value; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 6:</span> }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 7:</span>&nbsp; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 8:</span> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> ColorPickerThumb_DragDelta(<span style="color: rgb(0, 0, 255);">object</span> sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 9:</span> { </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 10:</span> <span style="color: rgb(0, 0, 255);">double</span> offsetX = 0; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 11:</span> <span style="color: rgb(0, 0, 255);">double</span> offsetY = 0;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 12:</span> </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 13:</span> offsetX = DistanceConverter.PixelsToValue(e.HorizontalChange, (pad.ActualWidth - colorPickerThumb.ActualWidth), (saturationSlider.Maximum - saturationSlider.Minimum)); </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 14:</span> offsetY = DistanceConverter.PixelsToValue(e.VerticalChange, (pad.ActualHeight - colorPickerThumb.ActualHeight), (luminanceSlider.Maximum - luminanceSlider.Minimum));</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 15:</span> </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 16:</span> <span style="color: rgb(0, 0, 255);">this</span>.dragDeltaX += offsetX; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 17:</span> <span style="color: rgb(0, 0, 255);">this</span>.dragDeltaY += -offsetY;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 18:</span> </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 19:</span> saturationSlider.Value = <span style="color: rgb(0, 0, 255);">this</span>.dragDeltaX; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: rgb(244, 244, 244);"><span style="color: rgb(96, 96, 96);"> 20:</span> luminanceSlider.Value = <span style="color: rgb(0, 0, 255);">this</span>.dragDeltaY; </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'courier new',courier,monospace; background-color: white;"><span style="color: rgb(96, 96, 96);"> 21:</span> }</pre> </div> </div> <p><object height="300" width="300" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAIAAACHwAAAh8AAAAAAAAAAAAAAAAAAGAAAAAvAEwAaQBiAHIAYQByAGkAZQBzAC8AUwBpAGwAdgBlAHIAbABpAGcAaAB0ACAAdABlAGEAbQAvAEMAbwBsAG8AcgBQAGkAYwBrAGUAcgBfADAAMgAuAHMAZgBsAGIAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" type="application/x-silverlight-2-b2"> <param name="source" value="/Libraries/Silverlight_team/ColorPicker_02.sflb"> <a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none;"> </a></object></p> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/ColorPicker_02_1.sflb">Download source</a></p> <p>Since we have the two slider's done, it is time do create the third component - the hue slider.</p> <p><img src="http://blogs.telerik.com/Libraries/Silverlight_team/hue_slider.sflb" /> </p> <p>This is an example of a hue slider from Expression Blend. <br /> <img src="http://blogs.telerik.com/Libraries/Silverlight_team/hue_slider_01.sflb" /> </p> <p>The hue slider has a little bit different responsibility that the saturation and luminance sliders. Besides updating the result box, the hue sliders takes care of updating the gradient background of the pad as well. <br /> Like the other two sliders, the value of the hue slider is used to convert from HSL to RGB. The interesting task here is to make the slider to look like the one on the last image. This means that we have to restyle the slider completely(track, thumb etc).</p> <p>After some time in Blend:</p> <p><object height="200" width="25" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAIAACVAgAArBQAAAAAAAAAAAAAAAAAAGAAAAAvAEwAaQBiAHIAYQByAGkAZQBzAC8AUwBpAGwAdgBlAHIAbABpAGcAaAB0ACAAdABlAGEAbQAvAEMAbwBsAG8AcgBQAGkAYwBrAGUAcgBfADAAMwAuAHMAZgBsAGIAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" type="application/x-silverlight-2-b2"> <param name="source" value="/Libraries/Silverlight_team/ColorPicker_03.sflb"> <a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none;"> </a></object></p> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/ColorPicker_03_1.sflb">Download source</a></p> <p>Since we have all the necessary parts to assemble a decent color picker, I'd like to spend just a little bit of time on the converter class that does the magic - <a href="http://blogs.telerik.com/Libraries/Silverlight_team/ColorConverter.sflb">ColorConverter.cs</a>. <strong>ColorConverter</strong> has one very important method called HSLtoRGB. Correct, this method takes 3 values - hue, saturation and luminance and return an object of type Color.</p> <p>This is the final result. Dragging the thumb and changing the value of the hue slider makes the result box change its color. Enjoy!</p> <object height="320" width="520" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAIAAC+NQAAEyEAAAAAAAAAAAAAAAAAAFoAAAAvAEwAaQBiAHIAYQByAGkAZQBzAC8AUwBpAGwAdgBlAHIAbABpAGcAaAB0ACAAdABlAGEAbQAvAEMAbwBsAG8AcgBQAGkAYwBrAGUAcgAuAHMAZgBsAGIAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" type="application/x-silverlight-2-b2"> <param name="source" value="/Libraries/Silverlight_team/ColorPicker.sflb"> <a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none;"> </a></object> <p><a href="http://blogs.telerik.com/Libraries/Silverlight_team/ColorPicker_1.sflb">Download source</a></p> http://blogs.telerik.com/KirilStanoev/Posts/08-08-06/how_to_color_picker_done_with_few_slider_controls.aspx Kiril Stanoev http://blogs.telerik.com/KirilStanoev/Posts/08-08-06/how_to_color_picker_done_with_few_slider_controls.aspx c9984c80-c205-4261-93a2-3d7b25cc58ac Wed, 06 Aug 2008 09:10:00 GMT Using ValueConverter to edit Slider's TickTemplate <p><span style="font-family: calibri;">RadSlider for Silverlight has a neat functionality that allows you to display tick marks along the track.</span></p> <p><img height="39" width="309" src="/Libraries/MetaBlog/1.sflb" alt="Slider control with default tick template" /></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;">But what if you are not pleased with the current design of the ticks? Of course you can completely change the look of a tick mark. Let’s say that instead of bluish rectangles, you want your ticks to be ellipses, or triangles maybe. This is easily achieved by setting the </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">TickTemplate</span><span style="font-family: calibri;"> property.</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> TickPlacement</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="BottomRight"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> TickFrequency</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="1"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Maximum</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="10"&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider.TickTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">DataTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">Grid</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">Ellipse</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Width</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="5"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Height</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="5"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Fill</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="Black"</span> <span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">/&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">Grid</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">DataTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider.TickTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 10pt;"><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p><img src="/Libraries/MetaBlog/2.sflb" />&nbsp;</p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;">Let’s take this a step further. Instead of shapes we might want to place some text underneath the track, displaying the months of the year for example. We could do that using a TemplateSelector and depending on the value of the tick to pick the right template, but this means that we have to have 12 different templates. </span></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;">A more elegant way of achieving the desired outcome is by using a ValueConverter. Since the numeric representation of each tick is given to its DataContext, all we need is the appropriate converter.</span></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;">Let’s start by setting some properties to our slider. Since we are going to display the name of the months, we need to set the </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">Maximum</span><span style="font-family: calibri;"> to </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">12</span><span style="font-family: calibri;"> and the </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">Minimum</span><span style="font-family: calibri;"> to </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">1</span><span style="font-family: calibri;">. Since the numeric representation of the months goes like 1, 2, 3…12 we have to set the </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">TickFrequency</span><span style="font-family: calibri;"> to </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">1</span><span style="font-family: calibri;">. Also we want the names of the months to appear bellow the track so </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">TickPlacement</span><span style="font-family: calibri;">has to be </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">BottomRight</span><span style="font-family: calibri;">. The next property is optional but since it is a show off why not use it. Let’s set the </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">IsSnapToTickEnabled </span><span style="font-family: calibri;">property to </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">True </span><span style="font-family: calibri;">and we are now ready to proceed with our TickTemplate.</span></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;">The TickTemplate consists of a </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">StackPanel </span><span style="font-family: calibri;">that has 2 children – an </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">Ellipse </span><span style="font-family: calibri;">and a </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">TextBlock</span><span style="font-family: calibri;">. The interesting stuff is that the </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">Text </span><span style="font-family: calibri;">property of the </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">TextBlock</span><span style="font-family: calibri;"> is bound and has a specific ValueConverter in it called </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">MonthNameConverter.</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> &nbsp;&nbsp;&nbsp;&nbsp; Maximum</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="12"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Minimum</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="1"</span> </p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TickFrequency</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="1"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> TickPlacement</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="BottomRight"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsSnapToTickEnabled</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="True"&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&nbsp;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider.TickTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">DataTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">StackPanel</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">Ellipse</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> &nbsp;&nbsp; Width</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="5"</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Height</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="5"</span> </p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fill</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="Black"</span> </p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HorizontalAlignment</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="Center"/&gt;</span></p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">TextBlock</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Text</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="{</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">Binding</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> Converter</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">={</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">StaticResource</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"> MonthNameConverter</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">}}"</span> </p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FontSize</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">="10"/&gt;</span></p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">StackPanel</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">DataTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider.TickTemplate</span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">&nbsp;</span></p> <p style="margin: 0in 0in 10pt;"><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">&lt;/</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">telerik</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">:</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);">RadSlider</span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);">&gt;</span></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;">One final step we should take is to actually implement this </span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);">MonthNameConverter. </span><span style="font-family: calibri;">Go to your code-behind file and create the following class:</span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);">public</span><span style="font-size: 10pt; font-family: 'courier new';"> <span style="color: rgb(0, 0, 255);">class</span> <span style="color: rgb(43, 145, 175);">MonthNameConverter</span> : <span style="color: rgb(43, 145, 175);">IValueConverter</span> <p><span><span><span>&nbsp;</span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span>{</span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">object</span> Convert(<span style="color: rgb(0, 0, 255);">object</span> value, <span style="color: rgb(43, 145, 175);">Type</span> targetType, <span style="color: rgb(0, 0, 255);">object</span> parameter, <span style="color: rgb(43, 145, 175);">CultureInfo</span> culture)</span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 128, 0);"><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get the numeric representation of the tick, cast it to int and</span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 128, 0);">// based on this int value, get the corresponding month name</span> </span></span></span> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(43, 145, 175);">CultureInfo</span>.CurrentCulture.DateTimeFormat.GetMonthName((<span style="color: rgb(0, 0, 255);">int</span>)(<span style="color: rgb(0, 0, 255);">double</span>)value);</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span><span><span><span>&nbsp;</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">object</span> ConvertBack(<span style="color: rgb(0, 0, 255);">object</span> value, <span style="color: rgb(43, 145, 175);">Type</span> targetType, <span style="color: rgb(0, 0, 255);">object</span> parameter, <span style="color: rgb(43, 145, 175);">CultureInfo</span> culture)</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 255);">throw</span> <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">NotImplementedException</span>();</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new';"><span><span><span><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 10pt;"><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new';"><span><span><span><span><span><span>}</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;"><span><span><span><span><span><span>Last but not least we have to reference MonthNameConverter in the XAML file. You can do this by creating a reference to your project:</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 10pt;"><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);"><span><span><span><span><span><span>xmlns</span></span></span></span></span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>:</span></span></span></span></span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(255, 0, 0);"><span><span><span><span><span><span>local</span></span></span></span></span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>="clr-namespace:UsingValueConverter"</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;"><span><span><span><span><span><span>Then in the </span></span></span></span></span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);"><span><span><span><span><span><span>UserControl.Resources </span></span></span></span></span></span></span><span style="font-family: calibri;"><span><span><span><span><span><span>attach a key to the converter.</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>&lt;</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);"><span><span><span><span><span><span>UserControl.Resources</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>&gt;</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);"><span><span><span><span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>&lt;</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);"><span><span><span><span><span><span>local</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>:</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(163, 21, 21);"><span><span><span><span><span><span>MonthNameConverter</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"><span><span><span><span><span><span> x</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>:</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(255, 0, 0);"><span><span><span><span><span><span>Key</span></span></span></span></span></span></span><span style="font-size: 10pt; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>="MonthNameConverter" /&gt;</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 10pt;"><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>&lt;/</span></span></span></span></span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(163, 21, 21);"><span><span><span><span><span><span>UserControl.Resources</span></span></span></span></span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: 'courier new'; color: rgb(0, 0, 255);"><span><span><span><span><span><span>&gt;</span></span></span></span></span></span></span></p> <p style="margin: 0in 0in 10pt;"><span style="font-family: calibri;"><span><span><span><span><span><span>Run the project and you output should look something like the following:</span></span></span></span></span></span></span></p> <span><span><span><span><span><span><img height="43" width="645" src="/Libraries/MetaBlog/3.sflb" /> </span></span></span></span></span></span> <p><span><span><span><span><span><span>&nbsp;</span></span></span></span></span></span></p> <p style="margin: 0in 0in 0pt; line-height: normal;"><span><span><span><span><span><span>&nbsp;</span></span></span></span></span></span></p> <h2 align="center"><span style="font-family: calibri;"></span></h2> <h2 align="center"><span style="font-family: calibri;"><span><span><span><span><span><span>Silverlight Test Page</span></span></span></span></span></span></span></h2> <p style="margin: 0in 0in 0pt; line-height: normal;"><span><span><span><span><span><span>&nbsp;</span></span></span></span></span></span></p> <object height="300" width="700" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAIAADYEwAA2BMAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" type="application/x-silverlight-2-b2"> <param name="source" value="/Libraries/Silverlight_team/UsingValueConverter (2).sflb"> <param name="background" value="white"> <span><span><span><span><span><span><a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none;"> </a></span></span></span></span></span></span></object></span></p> <p><span><span><span>&nbsp;</span></span></span></p> </span></p> http://blogs.telerik.com/KirilStanoev/Posts/08-07-24/using_valueconverter_to_edit_slider_s_ticktemplate.aspx Kiril Stanoev http://blogs.telerik.com/KirilStanoev/Posts/08-07-24/using_valueconverter_to_edit_slider_s_ticktemplate.aspx a3d87dfa-3811-4041-b2f4-dfc85f5475a7 Thu, 24 Jul 2008 02:00:00 GMT