在用xaml布局的時(shí)候,有時(shí)候?yàn)榱耸菇缑鎚etro化,有些button要使用圓形代替默認(rèn)的長(zhǎng)方形。以下的button樣式可以解決這個(gè)問題,可以根據(jù)自己的需要再加以修改。當(dāng)然如果你熟悉bland的話可以直接使用它來繪制你需要的樣式,但是貼代碼是否更快一點(diǎn)呢?
代碼如下:
<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>