Page 1 of 1

Styling buttons from codebehind

Posted: 08 May 2014, 00:13
by noesis_user
I am trying to apply style to a radio button from code behind. The style is defind in xaml as follows,
<Style x:Key="RadioButtonStyle2" TargetType="{x:Type RadioButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type RadioButton}">
                <Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Codebehind is :
Noesis::Gui::RadioButton* plugin_button = new Noesis::Gui::RadioButton();

Ptr<IResourceKey> key = ResourceKeyString::Create("RadioButtonStyle2");
Noesis::Gui::Style* style = main_root->FindResource<Noesis::Gui::Style>(key.GetPtr());
plugin_button->SetStyle(s);
It gives me weird linking errors although I am not missing anything as such. Can you please suggest?

Re: Styling buttons from codebehind

Posted: 08 May 2014, 11:52
by sfernandez
Could you please attach the link warnings you are getting?

Under which platform are you building your project?

P.S. Just an advice, in your C++ code you can use Ptr smart pointer to take care of object references. You have to write: "Ptr<Noesis::Gui::RadioButton> plugin_button = *new Noesis::Gui::RadioButton();". Then you don't need to delete this object manually, it will be deleted automatically when no references to the object are kept.