Welcome to the Xceed Community | Help
Community Search  
More Search Options

How to add the style dynamically for the xceed grid DataCell

Sort Posts: Previous Next
  •  08-17-2009, 3:10 AM Post no. 23359

    How to add the style dynamically for the xceed grid DataCell

    Hello,

           I am using User Control derived from the Xceed Grid. I want the style to be given dynamically for the Xceed DataCell. I dont want to give the xaml but want to add style in the .cs file dynamically.

    The code for the xaml for adding the style for xceed data cell:
     

    <Grid Name="gd">
            <Grid.Resources>

                  <Style TargetType="{x:Type xcdg:DataCell}">
                               <Setter Property="HorizontalContentAlignment" Value="Right"/>
                    </Style>

            </Grid.Resources>

     </Grid>

     

     

    I am getting the desired output but for some DataCell i want the Alignment as Left which i may get using the Data Trigger but i am making the UserControl so i want to set it dynamically how could i get the desired output?

    I tried using the code in .cs as below in the Constructor:


                Style st = new Style(typeof(Xceed.Wpf.DataGrid.DataCell));
               
                st.Setters.Add(new Setter(HorizontalAlignmentProperty, "Right"));

                gd.Resources.Add("StyleForDataCell", st);

     

    The above code is not working.

    Kindly answer the post.

     

    Thank You,

    Paras Sanghani

     

     


    Nothing Is Impossible
    Filed under: ,
  •  08-17-2009, 7:52 AM Post no. 23363 in reply to 23359

    Re: How to add the style dynamically for the xceed grid DataCell

    I am facing the same problem? Do we need to add the resource to .cs file?
  •  08-17-2009, 10:10 AM Post no. 23370 in reply to 23363

    Re: How to add the style dynamically for the xceed grid DataCell

    Well, this is not allowing us to add the style property dynamically as it is using Reflection.

    Kindly let me know if its possible to add the style dynamically in .cs file.


    Pratik Gohil
  •  08-25-2009, 7:02 AM Post no. 23506 in reply to 23370

    Re: How to add the style dynamically for the xceed grid DataCell

    I am looking for a solution to this also.  I tried the following code, but to no avail:

    Style stDataCell = new Style(typeof(ColumnManagerCell));
    DataTrigger ds = new DataTrigger();
    Binding bs = new Binding("MyField");
    bs.RelativeSource = RelativeSource.Self;
    ds.Binding = bs;
    ds.Value = "MyValue";
    ds.Setters.Add(new Setter(BackgroundProperty, Brushes.Aqua));
    stDataCell.Triggers.Add(ds);

    ColumnManagerRow columnManagerRow = FindVisualChild<ColumnManagerRow>(myDataGridControl);
    columnManagerRow.Cells[0].Style = stDataCell;

    // The following is alternative code I tried instead of the above two lines, but doesn't work either
    //stColumnManagerCell.Triggers.Add(ds);
    //myDataGridControl.Resources[typeof(DataCell)] = stDataCell;


    Associate, .NET Development
    Morgan Stanley, UK
  •  09-22-2009, 3:42 PM Post no. 24093 in reply to 23506

    Re: How to add the style dynamically for the xceed grid DataCell

    Please see my latest thread on this complete with example as I am trying to achieve the same but using XAML:

    http://xceed.com/CS/forums/thread/23535.aspx


    Associate, .NET Development
    Morgan Stanley, UK
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.