WPF CustomControl - Inherit RadGridView

4 posts, 0 answers
  1. Tuomas
    Tuomas avatar
    2 posts
    Member since:
    Jun 2013

    Posted 24 Sep 2013 Link to this post


    Im trying to create CustomGridView component by creating WPF CustomControl (control inherits telerik RadGridView). I realized that my custom control style is not loaded. I made simple example about this problem. Example should change my custom control background to blue but it does not.

    my cs. file
    public class MyCustomGridView : RadGridView  
         static MyCustomGridView()
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MyCustomGridView), new FrameworkPropertyMetadata(typeof(MyCustomGridView)));
         protected override void OnInitialized(EventArgs e)

    and here is my Generic.xaml in themes folder

    <Style TargetType="{x:Type local:MyCustomGridView}">   

    <Setter Property="Background" Value="Blue"></Setter>
     <Setter Property="Template">
    <ControlTemplate TargetType="{x:Type local:MyCustomGridView}">
                        <Border Background="{TemplateBinding Background}"    
                             BorderBrush="{TemplateBinding BorderBrush}"  
                               BorderThickness="{TemplateBinding BorderThickness}">
    </Setter>  </Style>

    So basically this is classic start for WPF custom control, but in runtime this is not working. Am I missing something ?

    Best regards

  2. Tuomas
    Tuomas avatar
    2 posts
    Member since:
    Jun 2013

    Posted 25 Sep 2013 Link to this post

    Got it working now. Weird thing is that my working solution is like above described, maybe there was typo or something.

    This thread helps no one / is not informative so this can be deleted.

  3. sandip
    sandip avatar
    1 posts
    Member since:
    Jan 2014

    Posted 14 Sep 2016 Link to this post

    I have same problem.

    My Grid is not showing at design time same as Runtime.

    Where is admin, Please help.

  4. Dilyan Traykov
    Dilyan Traykov avatar
    613 posts

    Posted 14 Sep 2016 Link to this post

    Hello Sandip,

    As stated in the Implict Styles article, custom controls will not automatically receive the inherited control style. You will have to base your custom style on the default style of the control that is inherited. Thus, you have to add the following line to your App.xaml file:

    <Style TargetType="my:MyCustomGridView" BasedOn="{StaticResource RadGridViewStyle}" />

    Please let me know if this solves your issue.

    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top