0

I try to apply a really simple ControlTemplate to a RadioButton. But that cause in a weird behavior. As Long as I´m just clicking the Label everything works fine, but when I click the button control itself it never changes again. Here the complete code of the control:

    <UserControl x:Class="RadioButtonDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
    <ControlTemplate TargetType="RadioButton" x:Key="RadioButtonTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="{TemplateBinding Content}"/>
            <RadioButton IsChecked="{TemplateBinding IsChecked}" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center"/>
        </Grid>
    </ControlTemplate>

    <Style TargetType="RadioButton" x:Key="RadioButtonStyle">
        <Setter Property="Template" Value="{StaticResource RadioButtonTemplate}"/>
    </Style>

</UserControl.Resources>
<StackPanel>
    <RadioButton Content="Textbox diabled" GroupName="Group1" Style="{StaticResource RadioButtonStyle}"/>
    <RadioButton x:Name="EnabledButton" Content="Textbox enabled" GroupName="Group1" Style="{StaticResource RadioButtonStyle}"/>
    <TextBox IsEnabled="{Binding IsChecked, ElementName=EnabledButton}"/>
</StackPanel>

Can someone help?

1 Answer 1

0

Please get default style from following link,

http://msdn.microsoft.com/en-us/library/cc296247(v=vs.95).aspx

Use the template by just swapping content and button(:-( code is bulk).

1
  • Well, that is far too big for me, but it worked. Question answered!
    – christoph
    Nov 6, 2013 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.