locked
Toolbar RadioButton Style RRS feed

  • Question

  • Hi,

    I really like what WPF does when you put a group of radio buttons on a toolbar.
    ie. It overrides the style of the radiobuttons and makes them look/behave like toggle buttons.

    I'm trying to acheive the exact same effect, but I don't want to use a toolbar (or more specifically have the toolbar visible).

    Right now, I'm just using a stackpanel (orientation=horizontal) to host my buttons (and radio buttons).

    Should I...

    a, Replace the stackpanel with a toolbar and hide the visual elements I don't want - the grab handles, overflow drop down etc.
    From what I've read, this is not as simple as you might think.  Especially hiding the overflow arrow.

    ... or ...

    b, Is there an easy way to 'borrow' the styles the toolbar applies to the radio buttons and just re-use them?


    I really would prefer option B but I don't know where to begin.


    Many thanks,





    MQCA
    Thursday, September 10, 2009 1:41 PM

Answers

  • You can use the Style key to achieve this:

    <RadioButton Style="{StaticResource {x:Static ToolBar.RadioButtonStyleKey}}" />


    http://weblogs.asp.net/marianor/
    • Proposed as answer by Bigsby Thursday, September 10, 2009 3:02 PM
    • Marked as answer by MQCA Thursday, September 10, 2009 3:31 PM
    Thursday, September 10, 2009 1:45 PM

All replies

  • You can use the Style key to achieve this:

    <RadioButton Style="{StaticResource {x:Static ToolBar.RadioButtonStyleKey}}" />


    http://weblogs.asp.net/marianor/
    • Proposed as answer by Bigsby Thursday, September 10, 2009 3:02 PM
    • Marked as answer by MQCA Thursday, September 10, 2009 3:31 PM
    Thursday, September 10, 2009 1:45 PM
  • If want the Style to change something you can always access a control style. Say you have ToolBar named toolBar and that its first item is a RadionButton.

    System.Windows.Markup.XamlWriter.Save((toolBar.Items[0] as System.Windows.Controls.RadioButton).Style)

    returns the Style XAML.

    Bigsby, Lisboa, Portugal - O que for, quando for, é que será o que é... http://bigsby.eu
    Thursday, September 10, 2009 3:04 PM