最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Silverlightbutton圖片切換樣式實例代碼

 更新時間:2013年11月01日 15:27:22   作者:  
這篇文章介紹了Silverlightbutton圖片切換樣式實例代碼,有需要的朋友可以參考一下

之前一直做WPF現(xiàn)在開始接觸Slilverlight感觸很多。

今天做一個Button要求

有兩個圖片,button默認有一個圖片,鼠標over時用另一個圖片,

用wpf做的時候?qū)懸粋€template很簡單,但silverlight和wpf寫起來不一樣

記錄一下。大概思路是兩個image鼠標MouseOver的時候一個Visible一個Collapsed

寫的是一個自定義控件,代碼和皮膚分離,很簡單的一個demo

代碼下載:ImageButtonTest.rar

先寫一個繼承自button的imagebutton類

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ImageButtonTest
{
    /// <summary>
    /// build by lp
    /// </summary>
    public class MyImageButton : Button
    {

        public static readonly DependencyProperty ImageNormalProperty =
            DependencyProperty.Register("ImageNormal",
                                        typeof(ImageSource),
                                        typeof(MyImageButton),
                                        new PropertyMetadata(null));

        public static readonly DependencyProperty ImageHoverProperty =
            DependencyProperty.Register("ImageHover",
                                        typeof(ImageSource),
                                        typeof(MyImageButton),
                                        new PropertyMetadata(null));
        //鼠標移到上面
        public ImageSource ImageHover
        {
            get { return (ImageSource)GetValue(ImageHoverProperty); }
            set { SetValue(ImageHoverProperty, value); }
        }
        //默認圖片
        public ImageSource ImageNormal
        {
            get { return (ImageSource)GetValue(ImageNormalProperty); }
            set { SetValue(ImageNormalProperty, value); }
        }

        public MyImageButton()
        {
            this.DefaultStyleKey = typeof(MyImageButton);
        }
    }
}

一個是鼠標移到上面的imageSource一個是默認的source

看一下它的樣式 用sotryboard控制

鼠標MouseOver的時候一個Visible一個Collapsed

復(fù)制代碼 代碼如下:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ImageButtonTest" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">


    <Style TargetType="local:MyImageButton">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:MyImageButton">
                    <Grid Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">

                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="mouseOverImage">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="normalImage">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed"/>
                                <VisualState x:Name="Disabled"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Image x:Name="normalImage" Source="{TemplateBinding ImageNormal}" Stretch="Fill"/>
                        <Image x:Name="mouseOverImage" Source="{TemplateBinding ImageHover}" Stretch="Fill" Visibility="Collapsed"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

這樣就可以用了

我們在頁面上調(diào)用一下

復(fù)制代碼 代碼如下:

<UserControl
    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"
    xmlns:local="clr-namespace:ImageButtonTest" x:Class="ImageButtonTest.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <local:MyImageButton   Margin="0" ImageHover="Images/全屏鼠標移上.png" ImageNormal="Images/全屏.png" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center">           
        </local:MyImageButton>
    </Grid>
</UserControl>

相關(guān)文章

  • 詳解免費開源的.NET多類型文件解壓縮組件SharpZipLib(.NET組件介紹之七)

    詳解免費開源的.NET多類型文件解壓縮組件SharpZipLib(.NET組件介紹之七)

    本篇文章主要介紹了免費開源的.NET多類型文件解壓縮組件SharpZipLib,這也是一種解壓縮組件,具有一定的參考價值,有興趣的可以了解一下。
    2016-12-12
  • asp.net模板引擎Razor中cacheName的問題分析

    asp.net模板引擎Razor中cacheName的問題分析

    這篇文章主要介紹了asp.net模板引擎Razor中cacheName的問題,實例分析了cacheName在提高編譯效率方面的使用技巧,需要的朋友可以參考下
    2015-06-06
  • 在C#中生成與PHP一樣的MD5 Hash Code的方法

    在C#中生成與PHP一樣的MD5 Hash Code的方法

    這篇文章主要介紹了如何在C#中生成與PHP一樣的MD5 Hash Code,需要的朋友可以參考下
    2014-05-05
  • ASP.net中實現(xiàn)基于UrlRewrite的防盜鏈功能

    ASP.net中實現(xiàn)基于UrlRewrite的防盜鏈功能

    這篇文章主要介紹了ASP.net中如何實現(xiàn)基于UrlRewrite的防盜鏈,需要的朋友可以參考下
    2014-03-03
  • .Net?core?Blazor+自定義日志提供器實現(xiàn)實時日志查看器的原理解析

    .Net?core?Blazor+自定義日志提供器實現(xiàn)實時日志查看器的原理解析

    我們經(jīng)常遠程連接服務(wù)器去查看日志,比較麻煩,如果直接訪問項目的某個頁面就能實時查看日志就比較奈斯了,結(jié)合blazor實現(xiàn)了基本效果,這篇文章主要介紹了.Net?core?Blazor+自定義日志提供器實現(xiàn)實時日志查看器,需要的朋友可以參考下
    2022-10-10
  • asp.net Md5的用法小結(jié)

    asp.net Md5的用法小結(jié)

    在ASP.NET中提供了加密的解決方法。在名字空間System.Web.Security中包含了類FormsAuthentication,其中有一個方法HashPasswordForStoringInConfigFile。
    2009-11-11
  • ASP.NET Web Page應(yīng)用深入探討

    ASP.NET Web Page應(yīng)用深入探討

    這些內(nèi)容是我在學習ASP.Net的時候?qū)age研究的一些心得,具體的細節(jié)沒有很詳細的探討,更多的內(nèi)容請大家參考MSDN,但是我舉了一些初學者常犯的錯誤和出現(xiàn)錯誤的原因,希望可以給大家?guī)韱l(fā)。
    2009-08-08
  • Visual?Studio?2022智能輔助編碼介紹

    Visual?Studio?2022智能輔助編碼介紹

    這篇文章介紹了Visual?Studio?2022智能輔助編碼,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-12-12
  • .net簡單使用Log4net的方法(多個日志配置文件)

    .net簡單使用Log4net的方法(多個日志配置文件)

    log4net是.net中常用的一個日志記錄工具,下面這篇文章主要給大家介紹了關(guān)于.net簡單使用Log4net的方法(多個日志配置文件),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧
    2018-11-11
  • asp.net jquery無刷新分頁插件(jquery.pagination.js)

    asp.net jquery無刷新分頁插件(jquery.pagination.js)

    采用Jquery無刷新分頁插件jquery.pagination.js 實現(xiàn)無刷新分頁效果:本示例Handler中采用StringBuilder的append方法追加HTML,小數(shù)據(jù)量可以,但是大數(shù)據(jù)或是布局常變,建議返回JSON格式的數(shù)據(jù),性能和靈活性更好,望使用者好好把握
    2013-01-01

最新評論

密山市| 钟祥市| 浮梁县| 达尔| 济阳县| 清新县| 竹北市| 阿鲁科尔沁旗| 五莲县| 宾阳县| 安康市| 天气| 永定县| 泰来县| 安阳县| 奉节县| 腾冲县| 石门县| 吉安县| 芜湖市| 镇宁| 莎车县| 通道| 日喀则市| 托里县| 临漳县| 万宁市| 嵊州市| 虎林市| 麻江县| 磐石市| 香河县| 平乐县| 宜昌市| 钟祥市| 平定县| 新化县| 新疆| 张家川| 永修县| 称多县|