.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Defining a custom style for a derived DataGrid

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :WPF
Hi all, Please tell me what I could be missing here. I am trying to define a very basic style for a derived DataGrid and it doesn't seem to take! In my dll project, I have this in the Generic.xaml: <Style TargetType="{x:Type local:MyDataGrid1}" BasedOn="{StaticResource {x:Type DataGrid}}"> <Setter Property="RowBackground" Value="#AAEAEFF4"/> <Setter Property="AlternatingRowBackground" Value="#00FFFFFF"/> </Style>  .. and this is how the derived grid is currently (pretty empty until I have this figured out): public class MyDataGrid1 : DataGrid   {     static MyDataGrid1()     {       DefaultStyleKeyProperty.OverrideMetadata(typeof(MyDataGrid1), new FrameworkPropertyMetadata(typeof(MyDataGrid1)));     }   } And in my Sample App's MainPage.xaml, I simply have this: <mygrids:MyDataGrid1 x:Name="dataGrid1" /> But, the alternating colors are not applied! Interestingly, in debugger I see that the properties are set to these values in this instance, but the for some reason while rendering, these values were not used! Please help. Thanks

View Complete Post

More Related Resource Links

DataGrid: Tailor Your DataGrid Apps Using Table Style and Custom Column Style Objects


One of the most enduring challenges in writing user interfaces is figuring out how to display large amounts of data efficiently and intuitively without bewildering the user. The problem becomes particularly thorny when the interface must reflect hierarchical relationships within the data that the user needs to modify. The Windows Forms DataGrid control gives developers a powerful and flexible tool to meet this challenge. This article explains its basic operations and shows how to extend the DataGrid to display columns of data in an application-appropriate manner.

Kristy Saunders

MSDN Magazine August 2003

Creating custom property on derived Page

I am attempting to accomplish the following during the creation of a Page derived from DerivedPage: <local:DerivedPage xmlns="..." xmlns:x="..." xmlns:local="..." MyProperty="My Value" Title="My Title"> ... </local:DerivedPage> You'll notice an extra property MyProperty in there. The code-behind is like this: class DerivedPage : Page { public string MyProperty { get; set; } ... } When I execute this, I get a null reference in InitializeComponent() when I create a Page derived from DerivedPage. I also tried making MyProperty a dependency property.  But I get the same results. How can I create a property for my new base-class that's set in the markup of my derived class. Thanks, ...Matt

Cant adjust Box size in Custom view with Box style implemented in sharepoint



i have a sharepoint view which has boxed style implemented to it. It displayes information in form of two boxes adjacent to each other on the site. the issue i am facing is that the two boxes are of unequal size. The left size box takes enough space and hence the box adjacent box has to squeez in the left over space.

how can i customise those according to  my needs. any help would be appreciated.

Thanks in advance



How to use a custom Property in style


hi, i have Class like that;

class CASUICombobox : System.Windows.Controls.ComboBox  

        private bool m_bShowShadow = false;
        public bool ShowShadow
            get { return m_bShowShadow; }
            set { m_bShowShadow = value; CreateShadow(); }

        DropShadowEffect m_Shadow;

        private void CreateShadow()
            if (ShowShadow && m_Shadow == null)
                m_Shadow = new DropShadowEffect();
                m_Shadow.ShadowDepth = 3;

Style Trigger On Custom DependencyProperty


Hello all.

I'm having trouble setting a Style Trigger on a custom DependencyProperty I have set up in a UserControl.

Here is my "DragWidth.xaml":

<UserControl x:Class="TouchScreenTest.Controls.DragWidget"

Edit a DataGrid row's style by Javascript when a control is clicked.


I have a datagrid I am working with which has a few columns, but one checkbox with a javascript onclientclip event.

I want to highlight the row that the checkbox is clicked, highlighting for the user that this record has changed.

I have a CSS Class of "GrdHiglight" that can be used to override the "GrdNorm" and "GrdAlt" classes, or if I have to manually change the style for the row that is fine.

How do I reference the one row which the checkbox resides in, in the datagrid, to modify this?

Urgent: AssemblyName of Class derived from Custom HTTPHandler


Hi everyone,

I have developed a custom http handler which calls a WCF service from within. However the parameters to be passed to the service would vary from request to request.

The parameters could be collected by firing an event. The developer can write an eventhandler for the event which will collect the parameters from any where as required and put it into a property exposed by handler.

This event handler could be written on a .cs page which inherits from the original handler.

When request for the page comes to the custom HTTPHandlerFactory I have created, it should create an instance of child class (of custom HTTPHandler) instead of the actual handler class. However, I only have the Type name of child class. The assembly name in which the type is, is not known as the assembly names keep changing.

I wanted to create an instance of the child class (of custom HTTPHandler ) in Handler factory through reflection and pass it on for processing. But the name of its assembly is not known. Is there a way out?

Thanks in Advance,



WPF DataGrid Style Templates to make it look like the Silverlight DataGrid



Many of you might have noticed that the WPF DataGrid looks very blah compared to the Silverlight DataGrid.

Here are the WPF DataGrid Screenshot and Silverlight DataGrid Screenshot.

See how in the Silverlight DataGrid the lines are better, there are alternating row backgrounds and the selected row also looks better.

I am surprised the WPF DataGrid doesn't use the same styles by default as the Silverlight.

Has anyone styles the WPF DataGrid to make it look like the Silverlight DataGrid and if so can you share the templates with me?

Or is there a built-in theme in WPF DataGrid that looks close to the Silverlight DataGrid?



Custom Controls derived from existing controls - overriding default property values


I have some (probably very basic) questions about developing custom controls.  I am wanting to derive a set of button controls, and the first one I have started on is a "DeleteButton", that has a additional property (DeleteConfirmationText) that is built into the OnClientClick attribute.  To get that added, I overrode the Render method as follows:

protected override void Render(HtmlTextWriter writer)
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, string.Format("return confirm('{0}');", this.DeleteConfirmationText));

This all works well.  Now, I will add some logic to make sure that there is some text in the DeleteConfirmationText property, but that isn't the intent of my question.

What I am also wanting to do is to override some of the default property values, so I added that to the default constructor:

public DeleteButton()
            // Default the command name, and the button text to "Delete".
            this.CausesValidation = false;
            this.CommandName = "Delete";
            this.Text = "Delete";

Now, in the designer in VS2008, and I look at the properties for the control, there isn'

How to drop Activities in Custom Activity Designer having custom style template?



I have designed a custom activity designer developed using Activity Designer XAML and using that in a rehosted Workflow environment on a WPF. I have changed the outer design of the Activity designer by setting the style template to my required style. If I do this, I am unable to add the activities to the custom activity having my custom activity designer.

Am I missing anything.? Please help me in this regard.

Thanks in advance,



Defining Custom time dimension


I have tried using the Server time dimension before, and SSAS is clever enough to break down every single time attributes in my dimension to the hierarchy.

The new requirement for me is to create a Date reference table that stores the day-month-year as well as FiscalMonth and FiscalYear. That means in the cube I can no longer use the server time dimension but have to use the new Date table.

I have created the Date table as a time dimension, but the attribute does not show the hierarchy at all when i use them inside the browser, it just shows unknown.

Is there an article that I can read up on how to define my own time dimension?

Presenting Data with the DataGridView Control in .NET 2.0 > Defining Custom Column and Cell

in this link u can find the explanation about how to bind image column at run time.

How Can I deploy custom ItemStyle xsl into Style Library without SharePoint Designer



I'm using WSPBuilder to develop one custom site, and now when I use Content Query Web Part to show my custom fields. Also, I have modified the ItemStyle.xsl and tried to deploy it into Style Library\XSL Style Sheet folder, but nothing affect. Still I can not retrieve my customized template name in

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

 <Module Name="BerryInternetStyle" List="116" Url="Style Library/XSL Style Sheets" Path="" RootWebOnly="FALSE">
  <!--<File Url="upzoneItemStyle.xsl" Type="GhostableInLibrary"/>-->
  <File Url="ItemStyle.xsl" Type="GhostableInLibrary" IgnoreIfAlreadyExists="true"/>

I also tried to set IgnoreIfAlreadyExists false, but failed.

So anybody could help me? how to deploy this ItemStyle.xsl into SharePoint then let CWQP retrieve its definition about Style Sheet.

Or Is there another solution that SharePoint can retrieve Style Template without ItemStyle.xsl file?




Defining own property within a style

Is there any way I can declare my own property in a stlyle... (But without subclassing...) For example...
<Style x:Key="myStyle" TargetType="Button">
      <Setter Property="MyBackground" Value="Orange" />
      <Setter Property="

Style a grid in a DataGrid


Does anyone know how to style cell/row borders(i.e. separators) in a DataGrid?

Setting borders on DataGridCell and DataGridRow does not do the trick. It just adds a new inner border

I can style separators in ColumnHeaders but cannot find anything that can do the same in the grid itself



Custom Controls in C# .NET

Embedding user controls in a Windows form is just like adding a simple button or text box that are already provided with .NET. These basic controls were written essentially like you code your own controls. Typically the controls you design are to be used in multiple forms or to modularize your code. These reasons help reduce the amount of code you have to type as well as make it easier for you to change your implementation. There should almost never be any reason to duplicate code because it leaves a lot of room for bugs. So, implementing functionality specific to your control in the control's source code is a good idea. This reduces code duplication as well as modularize your code, which is a good programming guideline.

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend