How to use telerik winform radbutton style for a wpf button

6 posts, 1 answers
  1. Venkat
    Venkat avatar
    3 posts
    Member since:
    Jul 2015

    Posted 25 Aug 2015 Link to this post

    Hi

    I am new to the telerik world. I am currently working in a code base that uses a mixture of Telerik winforms (15.1.331) and telerik wpf controls (15.1.401). The application has a custom tssp file for winform elements that sets elements in a style. It also uses builtin Expression-DarkTheme for all wpf controls. My goal is to make both winforms buttons and wpf buttons look the same. I would like to know what is the best approach?

    Is there a way to create a wpf button theme from the winform radbutton style in the tssp file and apply it across the solution?

    Thanks

    Venkat

  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 27 Aug 2015 Link to this post

    Hi Venkat,

    Since the Xaml styles and the xml in the custom style files are quite different in their structure there is no straight forward conversion between them. In order to achieve your requirement you will need to manually create the styles for the WPF button. You can use Expression Blend to create the styles or write them manually in the application's resources.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Venkat
    Venkat avatar
    3 posts
    Member since:
    Jul 2015

    Posted 31 Aug 2015 Link to this post

    Hi Martin

     Thank you for the reply. Is it possible for you to share a wpf button template example. Also if possible an example on how to add a customized button template, but leave the Expression-DarkTheme as default for the other elements.

     Thanks

    Venkat

  5. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 01 Sep 2015 Link to this post

    Hello Venkat,

    I attached a small example that demonstrates several of our controls with the Expression_Dark theme and a extracted, and customized template for the RadButton control. Note that I am using the Implicit Styles theming mechanism to apply the theme. I also commented the changes to the button's template that I've made. Basically, I used Visual Studio to extract the Style (including the template) of the button and placed it into a ResourceDictionary file. Then, I modified the style and merged the resource dictionary into the application's resources (the App.xaml file).

    Please give the project a try and let me know if it helps.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Venkat
    Venkat avatar
    3 posts
    Member since:
    Jul 2015

    Posted 14 Sep 2015 in reply to Martin Link to this post

    Hi Martin

     As i was mentioning since we have a combination of wpf and winforms we don't have App.xaml, we set the wpf theme in program.cs too. 1) So how do i add this custom button xaml in program.cs

    2) I have many wpf buttons within my software. So i don't want to do Style="{StaticResource RadButtonStyle1} in every button xaml tag. Is there a way to set this once and apply to all my buttons

  7. Answer
    Martin
    Admin
    Martin avatar
    1099 posts

    Posted 17 Sep 2015 Link to this post

    Hi Venkat,

    You can add the button using an implicit style. This is a style that is defined without an x:Key which applies it to all elements of the specified TargetType in the scope where the style is added. For example, if you have a UserControl with 10 Button elements and you define the following style, the style will be applied automatically to all 10 buttons.
    <UserControl.Resources>
        <Style TargetType="Button">
            <Setter Property="Background" Value="Red" />
        </Style>
    <UserControl.Resources>
    You can merge add the resource dictionary in the Resources of the UserControls hosted in your WinForms application.
    <UserControl.Resources>
        <ResourceDictionary Source="RadButtonCustomStyle.xaml"/>
    <UserControl.Resources>
    You can also do that in code using the Resources property of the UserControl.
    wpfHost.MyUserControl.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(@"/<YourDllName>;component/RadButtonCustomStyle.xaml", UriKind.Relative) });

    Please let me know if this information helps.


    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready