关于在silverlight 中自定义按钮的问题

自定义按钮中,我们主要使用的是style 中设置ControlTemplate中相关内容来完成的。实例代码如下:


    <UserControl.Resources>
        <Style x:Key="ButtonStyle1" targettype="Button">
            <Setter Property="Width" Value="70"/>
            <Setter Property="Height" Value="70"/>
            <Setter Property="HorizontalAlignment" Value="Right"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate targettype="Button">
                        <Grid>
                            <visualstatemanager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="normal"/>
                                    <VisualState x:Name="MouSEOver">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="0.8" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle" d:IsOptimized="True"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="rectangle">
                                                <discreteObjectKeyFrame KeyTime="0">
                                                    <discreteObjectKeyFrame.Value>
                                                        <Thickness>-2</Thickness>
                                                    </discreteObjectKeyFrame.Value>
                                                </discreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="disabled"/>
                                </VisualStateGroup>
                            </visualstatemanager.VisualStateGroups>
                            <Rectangle x:Name="rectangle" Fill="{TemplateBinding Background}" RadiusY="20" RadiusX="20" stroke="Black" ToolTipService.ToolTip="{TemplateBinding Tag}" strokeThickness="0"/>  <!--这里主要是用来绑定Button中的Background属性,可是绑定一张图片-->
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>


上面定义了button的样式,下面主要在button中引用样式,示例如下:


        <telerik:RadButton Margin="0,10,164,20" Name="radButton2" Style="{StaticResource ButtonStyle1}" ToolTipService.ToolTip="*********">
            <telerik:RadButton.Background>
                <ImageBrush ImageSource="图片路径" />             </telerik:RadButton.Background>         </telerik:RadButton>

相关文章

如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的...
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,...
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如...
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不...
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:...
我需要根据Silverlight中的某些配置值设置给定控件的Style.我...