This is a migrated thread and some comments may be shown as answers.

WPF CustomControl - Inherit RadGridView

5 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tuomas
Top achievements
Rank 1
Tuomas asked on 24 Sep 2013, 08:49 AM
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


5 Answers, 1 is accepted

Sort by
0
Tuomas
Top achievements
Rank 1
answered on 25 Sep 2013, 06:24 AM
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!
0
sandip
Top achievements
Rank 1
answered on 14 Sep 2016, 08:14 AM

I have same problem.

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

Where is admin, Please help.

0
Dilyan Traykov
Telerik team
answered on 14 Sep 2016, 10:13 AM
Hello Sandip,

As stated in the 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.
0
Umang
Top achievements
Rank 1
answered on 25 Sep 2018, 05:19 AM

Hello Dilyan

I get the same problem and I also try to add this

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

 a line in my app.xaml file but it's not working. I have the same code as above mention by Tuomas but still, it's not working. Please provide another solution if it's possible.

0
Dilyan Traykov
Telerik team
answered on 25 Sep 2018, 11:28 AM
Hello Umang,

I'm afraid I cannot think of another reason why the aforementioned issue could occur.

Could you please have a look at the project I've attached to my reply and let me know how it differs from the one you have at your end?

Thank you in advance for your cooperation.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Tuomas
Top achievements
Rank 1
Answers by
Tuomas
Top achievements
Rank 1
sandip
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Umang
Top achievements
Rank 1
Share this question
or