• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
works guo

成功的渴望与生俱来---- 成功是获得赞美与尊重的最有效的途径
博客园    首页    新随笔    联系   管理    订阅  订阅

Image Button example

Image Button example

Here's an example I made real quick to get you started. 

<Style TargetType="Button"
                x:Key="styleA">
            <Setter Property="Template">
               <Setter.Value>
                  <ControlTemplate TargetType="Button">
                     <Grid x:Name="RootElement"
                           Background="Transparent">
                        <Grid.Resources>
                           <Storyboard x:Key="MouseOver State">
                             
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleX"
                                               To="1.2"
                                               Duration="00:00:00.25"/>
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleY"
                                               To="1.2"
                                               Duration="00:00:00.25" />
                           </Storyboard>

                           <Storyboard x:Key="Normal State">

                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleX"
                                               To="1"
                                               Duration="00:00:00.25" />
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleY"
                                               To="1"
                                               Duration="00:00:00.25" />
                           </Storyboard>
                          
                           <Storyboard x:Key="Pressed State">

                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleX"
                                               To="1.4"
                                               Duration="00:00:00.25" />
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleY"
                                               To="1.4"
                                               Duration="00:00:00.25" />
                           </Storyboard>


                        </Grid.Resources>
                        <ContentPresenter Content="{TemplateBinding Content}"
                                          RenderTransformOrigin="0.5,0.5">
                           <ContentPresenter.RenderTransform>
                              <ScaleTransform x:Name="buttonScale" />
                           </ContentPresenter.RenderTransform>
                        </ContentPresenter>
                     </Grid>
                  </ControlTemplate>                 
               </Setter.Value>
              
            </Setter>
         </Style>

 You'll want to affect the content of the button to what you need, for example :

 <Button Width="100"
              x:Name="buttonTest"
              Style="{StaticResource styleA}"
              Click="buttonTest_Click">
         <StackPanel Orientation="Vertical">
            <Image Source="image1.jpg" />
            <TextBlock Text="Test 1" />
         </StackPanel>
      </Button>

Modify the storyboard states to reflect what you need for your RenderTransform etc...

 Hope this helps ! If it did, remember to mark the post as answered !

posted @ 2008-04-02 19:59  works guo  阅读(606)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3