SilverLight中ImageButton控件制作方法

SilverLight中ImageButton控件制作方法,第1张

概述SilverLight中ImageButton控件制作方法 ---------------------------------------------------------------------------------- public partial class ImageButton : UserControl     {         public event EventHandler

Silverlight中Imagebutton控件制作方法

----------------------------------------------------------------------------------

public partial class Imagebutton : UserControl
    {
        public event EventHandler Click = null;
        public Imagebutton()
        {
            InitializeComponent();

            this.MouseleftbuttonDown += new MousebuttonEventHandler(Imagebutton_MouseleftbuttonDown);
            this.MouseleftbuttonUp += new MousebuttonEventHandler(Imagebutton_MouseleftbuttonUp);
            this.MouseEnter += new MouseEventHandler(Imagebutton_MouseEnter);
            this.MouseLeave += new MouseEventHandler(Imagebutton_MouseLeave);
            this.SizeChanged += new SizeChangedEventHandler(Imagebutton_SizeChanged);

            this.image1.margin = new Thickness(0,0);
            if (this.ImageSourcenormal != null)
            {
                this.image1.source = this.ImageSourcenormal;
                //this.LayoutRoot.Background = this.ImageSourcenormal as DependencyObject;
            }
            Imagebutton_SizeChanged(null,null);
        }

        private voID Imagebutton_SizeChanged(object sender,SizeChangedEventArgs e)
        {
            this.image1.WIDth = this.WIDth;
            this.image1.Height = this.Height;
        }
        private voID Imagebutton_MouseLeave(object sender,MouseEventArgs e)
        {
            if (this.ImageSourcenormal != null)
            {
                this.image1.source = this.ImageSourcenormal;
            }
        }
        private voID Imagebutton_MouseEnter(object sender,MouseEventArgs e)
        {
            if (this.ImageSourceOverlap != null)
            {
                this.image1.source = this.ImageSourceOverlap;
            }
        }
        private voID Imagebutton_MouseleftbuttonDown(object sender,MousebuttonEventArgs e)
        {
            if (this.ImageSourceDown != null)
            {
                this.image1.source = this.ImageSourceDown;
            }
        }
        private voID Imagebutton_MouseleftbuttonUp(object sender,MousebuttonEventArgs e)
        {
            if (this.ImageSourceOverlap != null)
            {
                this.image1.source = this.ImageSourceOverlap;
            }
            //单击事件
            if (this.Click != null)
            {
                this.Click(sender,e);
            }
        }


        //定义正常显示图片源
        public ImageSource ImageSourcenormal
        {
            get { return base.GetValue(ImageSourcenormalProperty) as ImageSource; }
            set
            {
                base.SetValue(ImageSourcenormalProperty,value);
                this.image1.source = value;
            }
        }
        public static Readonly DependencyProperty ImageSourcenormalProperty = DependencyProperty.Register("ImageSourcenormal",typeof(ImageSource),typeof(Imagebutton),new PropertyMetadata(null));
       
        //定义Overlap显示图片源
        public ImageSource ImageSourceOverlap
        {
            get { return base.GetValue(ImageSourceOverlapProperty) as ImageSource; }
            set { base.SetValue(ImageSourceOverlapProperty,value); }
        }
        public static Readonly DependencyProperty ImageSourceOverlapProperty = DependencyProperty.Register("ImageSourceOverlap",new PropertyMetadata(null));
       
        //定义Down显示图片源       
        public ImageSource ImageSourceDown
        {
            get { return base.GetValue(ImageSourceDownProperty) as ImageSource; }
            set { base.SetValue(ImageSourceDownProperty,value); }
        }
        public static Readonly DependencyProperty ImageSourceDownProperty = DependencyProperty.Register("ImageSourceDown",new PropertyMetadata(null));
       
    }

 

Imagebutton.xaml

------------------------------------------------------------

<UserControl x:Class="SlApp.Controls.Imagebutton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="227" d:DesignWIDth="321">        <GrID x:name="LayoutRoot" Height="192" WIDth="278">        <Image Height="168" HorizontalAlignment="left" margin="0,0" name="image1" Stretch="Fill" VerticalAlignment="top" WIDth="254" />        <GrID.Background>            <ImageBrush />        </GrID.Background>    </GrID></UserControl>

总结

以上是内存溢出为你收集整理的SilverLight中ImageButton控件制作方法全部内容,希望文章能够帮你解决SilverLight中ImageButton控件制作方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1032705.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存