Add an icon to ChildWindow in Silverlight

Source: Internet
Author: User

First: idea: 1. A subclass MyChildWindow 2 is derived from ChildWindow. add an image attribute to MyChildWindow: Source 3. create a TestChildWindow XAML 4 from MyChildWindow. redefine the style and add an Image object to bind Source and Image. port the defined style to the MyChildWindow Class 6. completion 1. A subclass MyChildWindow 2 is derived from ChildWindow. add an image attribute to MyChildWindow: Source code: [csharp] public class MyChildWindow: ChildWindow {public MyChildWindow () {} www.2cto.com public static DependencyProperty SourceProperty = De PendencyProperty. register ("Source", typeof (ImageSource), typeof (MyChildWindow), null); public ImageSource Source {get {return (ImageSource) (base. getValue (MyChildWindow. sourceProperty);} set {base. setValue (MyChildWindow. sourceProperty, value) ;}} 3. then, create a XAML: [html] <controls: MyChildWindow x: Class = "SilverlightApplication1.ChildWindow2" xmlns = "http: // sch of TestChildWindow Emas.micro soft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: controls =" clr-namespace: silverlightApplication1 "Width =" 400 "Height =" 300 "Title =" ChildWindow2 "Source ="/SilverlightApplication1; component/images/1.png"> <Grid x: name = "LayoutRoot" Margin = "2"> <Grid. rowDefinitions> <RowDefinition/> <RowDefinition Height = "Auto"/> </Grid. rowDefinitions> <Ton x: Name = "CancelButton" Content = "cancel" Click = "CancelButton_Click" Width = "75" Height = "23" HorizontalAlignment = "Right" Margin = "0, 12, 0, 0 "Grid. row = "1"/> <Button x: name = "OKButton" Content = "OK" Click = "OKButton_Click" Width = "75" Height = "23" HorizontalAlignment = "Right" Margin = "0,12, 79,0" Grid. row = "1"/> </Grid> </controls: MyChildWindow> CS: [csharp] public partial class ChildWindow2: MyChildWindow {pu Blic ChildWindow2 () {InitializeComponent ();} private void OKButton_Click (object sender, RoutedEventArgs e) {this. dialogResult = true;} private void CancelButton_Click (object sender, RoutedEventArgs e) {this. dialogResult = false ;}} use Blend to modify the style. For example, bind the image Source 5. port the defined style to the MyChildWindow class project to create the Theme directory and Generic. the xaml file copies the style to Generic. modify TargetType = "local: MyChildWindow" in xaml to update the MyChildWindow class. Constructor: [csharp] public MyChildWindow () {this. defaultStyleKey = typeof (MyChildWindow);} 6. create a ChildWindow and modify the XAML and CS code!

Related Article

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.