2012-08-22 65 views
0

我正在爲我的WPF應用程序開發Ribbon,我需要將兩個RibbonRadioButton添加到RibbonGroup中。我已經這樣做了,一切完美的作品:更改RibbonRadioButton的外觀

<rb:RibbonGroup> 

    <rb:RibbonRadioButton Label="Option one" IsChecked="{Binding OptionOne}" /> 
    <rb:RibbonRadioButton Label="Option two" IsChecked="{Binding OptionTwo}" /> 

</rb:RibbonGroup> 

但RibbonRadioButtons看起來像一個「常規按鈕」,我需要他們看起來像經典被按壓單選按鈕我們都知道這是由的一個小圓圈和一個標籤。

所以,有沒有辦法來改變RibbonRadioButtons的外觀?

在此先感謝

回答

1

這爲我工作:

<rb:RibbonMenuButton.Resources> 
    <ControlTemplate x:Key="RibbonRadioButtonControlTemplate1" TargetType="{x:Type rb:RibbonRadioButton}"> 
     <RadioButton GroupName="{Binding Name, RelativeSource={RelativeSource AncestorType=rb:RibbonGroup}}" Content="{TemplateBinding Label}" IsChecked="{Binding IsChecked}"/> 
    </ControlTemplate> 
</rb:RibbonMenuButton.Resources> 

    <rb:Ribbon HorizontalAlignment="Left" Margin="111,86,0,88.867" Width="289.14"> 
    <rb:RibbonGroup x:Name="grp1"> 
     <rb:RibbonRadioButton Label="Option one" IsChecked="{Binding OptionOne}" Template="{DynamicResource RibbonRadioButtonControlTemplate1}" /> 
     <rb:RibbonRadioButton Label="Option two" IsChecked="{Binding OptionTwo}" Template="{DynamicResource RibbonRadioButtonControlTemplate1}" /> 
    </rb:RibbonGroup> 
    </rb:Ribbon> 
+0

爲了得到這個工作,我必須將'IsChecked'屬性上的綁定更改爲以下內容,以便它可以找到正確的源:'{Binding IsChecked,RelativeSource = {RelativeSource AncestorType = {x:Type Ribbon: RibbonRadioButton}}}'。 – Sheridan

1

下面是標準的單選按鈕的模板:http://msdn.microsoft.com/en-us/library/ms751600.aspx

編輯:

我以爲RibbonRadioButton是你自己控制;但它是.net 4.5中的新功能!我無法找到它在MSDN模板的,所以我想你必須通過混合得到它。將控件放在新的Blend WPF項目的新窗口上;右鍵單擊設計視圖上的控件 - >編輯模板 - >編輯副本;那麼你可以編輯該模板中的「XAML視圖」 ......

+0

謝謝回答,但這種風格似乎沒有一個'RibbonRadioButton' – Dante

+0

我編輯我的回答工作 – franssu

+0

+1爲混合方向,如果你沒有混合,雖然你總是可以通過在VS的解決方案,比如x字符串做搜索:主要=「RibbonControlStyle」,你應該能夠找到默認模板的方式也。 –