在用xaml布局的时候,有时候为了使界面metro化,有些button要使用圆形代替默认的长方形。以下的button样式可以解决这个问题,可以根据自己的需要再加以修改。当然如果你熟悉bland的话可以直接使用它来绘制你需要的样式,但是贴代码是否更快一点呢?
代码如下:
<style x:key=btnnext targettype=button>
<setter property=template>
<setter.value>
<controltemplate targettype=button>
<grid>
<visualstatemanager.visualstategroups>
<visualstategroup x:name=commonstates>
<visualstate x:name=pressed>
<storyboard>
<objectanimationusingkeyframes storyboard.targetproperty=(frameworkelement.margin) storyboard.targetname=rectangle>
<discreteobjectkeyframe keytime=0>
<discreteobjectkeyframe.value>
<thickness>-3</thickness>
</discreteobjectkeyframe.value>
</discreteobjectkeyframe>
</objectanimationusingkeyframes>
</storyboard>
</visualstate>
<visualstate x:name=normal/>
<visualstate x:name=disabled/>
<visualstate x:name=mouseover/>
</visualstategroup>
<visualstategroup x:name=focusstates>
<visualstate x:name=focused/>
</visualstategroup>
</visualstatemanager.visualstategroups>
<rectangle x:name=rectangle radiusy=25 radiusx=25 stroke=blue strokethickness=4>
</rectangle>
<contentpresenter horizontalalignment={templatebinding horizontalcontentalignment} verticalalignment={templatebinding verticalcontentalignment}/>
</grid>
</controltemplate>
</setter.value>
</setter>
<setter property=margin value=5/>
<setter property=width value=50/>
<setter property=height value=50/>
<setter property=fontsize value=120/>
<setter property=foreground value=white/>
</style>