Style Silverlight ScrollViewer With A New ControlTemplate
In an earlier post I showed you how to add ScrollViewer to Panels. In this post I will show you how to change the look of the ScrollViewer using Expression Blend. I will work with the same example where I placed ScrollViewer for a StackPanel. Here is the XAML I will use with a screenshot of its output.
<ScrollViewer> <StackPanel x:Name="LayoutRoot" Background="Honeydew"> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkBlue" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkRed" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkGoldenrod" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkSeaGreen" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DodgerBlue" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkGreen" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkMagenta" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkOrchid" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkTurquoise" /> <Rectangle Margin="5" Width="270" Height="40" Fill="DarkViolet" /> </StackPanel> </ScrollViewer>
I will now show you how to modify the standard look of the ScrollViewer. Rather than killing myself by typing all the XAML required to achieve the goal, I will use Blend which makes doing this a breeze. In the Objects and Timeline I can see the hierarchy of Controls in my Page.
What I need to do now is change the default Control Template for ScrollViewer. This can be done by right clicking ScrollViewer in Objects and Timeline –> Edit Control Parts (Template) –> Edit a Copy.
My Objects and Timeline shows me the hierarchy of controls involved in a ScrollViewer. I now need to modify the template for VerticalScrollBar. This can be done by right clicking VierticalScrollBar –> Edit Control parts (Template) –> Edit a Copy.
In Objects and Timeline I now see this hierarchy.
To keep things simple, I will just change the background of my ScrollViewer. This can be done by applying a Radial gradient to the first Rectangle (highlighted above).
Screenshot below shows the changed background for ScrollViewer in Expression Blend.
Now when I run my application I can see that the background of my ScrollViewer has a Radial gradient applied to it.
Similarly we can changes other parts of the ScrollViewer such as top and bottom buttons and the thumb. Silverlight allows us to change look of controls significantly by editing Control Templates. You saw an example of this awesomeness in this article.
One Response to Style Silverlight ScrollViewer With A New ControlTemplate
Leave a Reply Cancel reply
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML


Hi, at http://www.xamltemplates.net/sl you can see a demo for a complete theme made in Silverlight you also find on the website themes for all the WPF controls