Silverlight仿Flash换肤一种简单实现方法

前阵子一个偶然的机会看到一个音乐视听的网站

这网站全用flash实现,一直对Silverlight比较关注,一直在学习,于是想用Silverlight模仿其做一个

业余折腾了两晚上,弄出来个界面UI的换肤实现,现在分享出来给大家,希望给大家带来抛砖引玉的效果

效果如下:点击右上角的5个皮肤会换到相应的皮肤样式,附带了一些动画效果,待我整理一下附上代码

获取 Microsoft Silverlight

程序也有几个bug,当浏览器大小变化时相应的UI大小没变,这个问题也好解决,留给大家了,呵呵

上关键代码颜色转化类:

根据索引得到相应的的画刷

 static public class SkinColor
    {

 


        static string[] topcolorintro = { "5f8ac1", "bd0000", "1d4598", "1f2537", "ffffff" };
        static string[] topcolor = { "81aadc", "150000", "041537", "000000", "ffffff" };
        static string[] memubgcolor = { "ffffff", "dd0000", "5c8730", "656c7b", "e1ecfe" };
        static string[] memulanbgcolor = { "cbdbee", "440000", "14316f", "222530", "c3d9ff" };
        static string[] bgcolor1 = { "5e86b8", "280000", "0840a9", "010203", "ffffff" };
        static string[] bgcolor2 = { "9abbe3", "680000", "0161c9", "131829", "ffffff" };


        static string[] bottombg = { "cbdbee", "440000", "14316f", "222530", "c3d9ff" };

        static string[] bottomMiddle = { "81aadc", "150000", "041537", "000000", "ffffff" };

      

        static public void SetColor(int cindex)
        {
            SkinType.color = cindex;   
        }

        static public SolidColorBrush GetTopIntroBrush()
        {
            return new SolidColorBrush(qxsl.Tools.Common.ToColor(topcolorintro[SkinType.color]));
        }

        static public SolidColorBrush GetBottomBrush()
        {
            return new SolidColorBrush(qxsl.Tools.Common.ToColor(bottombg[SkinType.color]));
        }
        static public SolidColorBrush GetBottomMiddleBrush()
        {
            return new SolidColorBrush(qxsl.Tools.Common.ToColor(bottomMiddle[SkinType.color]));
        }
        static public SolidColorBrush GetTopBrush()
        {
            return new SolidColorBrush(qxsl.Tools.Common.ToColor(topcolor[SkinType.color]));
        }

        static public SolidColorBrush GetMenuBgBrush()
        {
            return new SolidColorBrush(qxsl.Tools.Common.ToColor(memubgcolor[SkinType.color]));
        }

        static public SolidColorBrush GetMemuLanbgBrush()
        {
            return new SolidColorBrush(qxsl.Tools.Common.ToColor(memulanbgcolor[SkinType.color]));
        }

        static public LinearGradientBrush GetbgBrush()
        {
            LinearGradientBrush gradient = new LinearGradientBrush();
            gradient.StartPoint = new Point(0, 0);
            gradient.EndPoint = new Point(0, 1);

            GradientStop color1 = new GradientStop();
            color1.Color = qxsl.Tools.Common.ToColor(bgcolor1[SkinType.color]);
            color1.Offset = 0.2;
            gradient.GradientStops.Add(color1);

            GradientStop color2 = new GradientStop();
            color2.Color = qxsl.Tools.Common.ToColor(bgcolor2[SkinType.color]);
            color2.Offset = 0.8;
            gradient.GradientStops.Add(color2);
            return gradient;
        }

       

 

 

    }

//然后在各控件中

 public void SetColor()
        {
            this.Background = SkinColor.GetMemuLanbgBrush();
        }

提到相应的皮肤颜色,代码比较简陋,没整理过

惯例,附上代码,希望大家喜欢

下载

 

posted @ 2010-06-12 17:41  glory.xu  阅读(2403)  评论(7编辑  收藏  举报