Silverlight background Setting button solid color background

Source: Internet
Author: User
Tags silverlight

The Silverlight button directly sets its background to a color that often does not reach the effect. Because its built-in template puts the button background into a gradient brush. So if you want a solid color background, modify its template.

The code to modify the template in the background is as follows:

StringBuilder sb = new StringBuilder ();
Sb. Append ("<controltemplate xmlns= ' http://schemas.microsoft.com/winfx/2006/xaml/presentation ' xmlns:x= '/http Schemas.microsoft.com/winfx/2006/xaml ' ");
Sb. Append ("Xmlns:data= ' clr-namespace:system.windows.controls;assembly=system.windows.controls.data ' xmlns:mc= ' http ://schemas.openxmlformats.org/markup-compatibility/2006 ' ");
Sb. Append ("targettype= ' button ' >");
Sb. Append ("<border x:name=\" Border\ "background=\" {TemplateBinding background}\ "><contentpresenter Verticalalignment=\ "Center\" horizontalalignment=\ "left\"/></border> ");
Sb. Append ("</ControlTemplate>");

ControlTemplate ct = xamlreader.load (sb.) ToString ()) as ControlTemplate;
Btn. Template = ct;
Btn. Foreground = new SolidColorBrush (colors.white);
Btn. Background = new SolidColorBrush (Color.FromArgb (0xFF, 0x49, 0xa9, 0x8d));

Silverlight background Setting button solid color background

Contact Us

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

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

A Free Trial That Lets You Build Big!

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

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

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