Bug: Can't set complex content of RadButton with a style

3 posts, 1 answers
  1. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 05 Jul 2012 Link to this post

    Hello,
    here is a sample Silverlight page that shows the problem.
    To use it, just create a new Silverlight application and replace Page.xaml with the following code:
    <?xml version='1.0' encoding='utf-8' ?>
    <UserControl
      x:Class="SilverlightApplication1.MainPage"
      mc:Ignorable="d"
      d:DesignHeight="300" d:DesignWidth="400">
     
      <StackPanel>
        <StackPanel.Resources>
     
          <Style x:Key="Button3" TargetType="tk:RadButton">
            <Setter Property="Content" Value="Button 3" />
          </Style>
     
          <Style x:Key="Button4" TargetType="tk:RadButton">
            <Setter Property="Content">
              <Setter.Value>
                <TextBlock Text="Button 4" />
              </Setter.Value>
            </Setter>
          </Style>
     
        </StackPanel.Resources>
         
        <tk:RadButton Content="Button 1" />
     
        <tk:RadButton>
          <tk:RadButton.Content>
            <TextBlock Text="Button 2" />
          </tk:RadButton.Content>
        </tk:RadButton>
     
        <tk:RadButton Style="{StaticResource Button3}" />
     
        <tk:RadButton Style="{StaticResource Button4}" />
     
      </StackPanel>
    </UserControl>

    As you can see in the designer, and running the application, the fourth button has no content!
    Normally, each button should show its content, which is defined properly.
    This bug is very annoying because I can't define buttons with complex content with a style.
    Do you have a workaround, excepted defining each button manually?
    Patrick
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 09 Jul 2012 Link to this post

    Hello Patrick,

     I guess this is a Framework Limitation. You can see that the native Button has the same behavior:

    <Style x:Key="Button4" TargetType="Button">
                    <Setter Property="Content">
                        <Setter.Value>
                            <TextBlock Text="Button 4" />
                        </Setter.Value>
                    </Setter>
                </Style>
    <Button Style="{StaticResource Button4}" />
    This button behaves the same way - no Textblock is shown.
    For this scenario and for complex controls in the Content you can use a ContentTemplate like so:
    <Style x:Key="Button4" TargetType="telerik:RadButton">
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <TextBlock Text="Button 4" />
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
    <telerik:RadButton Style="{StaticResource Button4}" />

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 15 Jul 2012 Link to this post

    Thank you Petar, it is working fine.
    That's really an annoying bug in Silverlight!
    Patrick
Back to Top