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

    Hello!

    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)
         {         
            base.OnInitialized(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">
             <Setter.Value>   
                 
    <ControlTemplate TargetType="{x:Type local:MyCustomGridView}">
                        <Border Background="{TemplateBinding Background}"    
                             BorderBrush="{TemplateBinding BorderBrush}"  
                               BorderThickness="{TemplateBinding BorderThickness}">
                        </Border>          
           
    </ControlTemplate>      
           
    </Setter.Value>      
       
    </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.

    Cheers!
  3. UI for WPF is Visual Studio 2017 Ready
  4. sandip
    sandip avatar
    1 posts
    Member since:
    Jan 2014

    Posted 14 Sep Link to this post

    I have same problem.

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

    Where is admin, Please help.

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 14 Sep 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.

    Regards,
    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