In a XamWebGrid on Cell level (CellControlAttached event) im trying to change a cells style "in codebehind".
doing :
------------
Syle s = new Style(typeof(CellControl));
s.Setters.Add(
new Setter(CellControl.FontWeightProperty, FontWeights.Bold));
e.Cell.Style = s;
--------------
- works fine.
Question : How come doing :
new Setter(CellControl.HorizontalContentAlignmentProperty, HorizontalAlignment.Right));
-before applying the style, does not work ?
Hi,
The HorizontalContentAlignment and VerticalContentAlignment properties are actually dictated by the Column. So, no matter what you set the property to be on an individual cell, it will go back to what the column dictates.
Column.HorizontalContentAlignment, Column.VerticalContentAlignment.
-SteveZ
Does this mean it is not possible to set different alignment for the content on different rows in the same column in XamWebGrid ?
In general we have quite high demands for customization of "look and feel" all the way down to Cell level in the app we are creating. I have earlier asked about FormatString on a cell level and gotten a reply that this is not supported on a lower level then Column, and now these properties are not supported on a lower level then column either ?
- Can you please comment on this with respect to what we can expect from coming versions of this grid component when it comes to freedom to style on Column, Row and Cell level. (Including mentioned FormatString, and HorizontalContentAlignment, VerticalContentAlignment, etc etc )
- Can you also comment on the plans for implementing a cell merge function. ( which we also need badly)
Having full freedom to style on independent Column, Row and Cell level is for us so important that its the deciding point when it comes to choosing component to work with for the future. Knowing this is the first version of the grid compoent on the Silverlight platform makes us ofcourse more patient when it comes to missing functionality, but it would be nice with some "roadmap" indications when it comes to these details.
regards
Oyvind Johnsen
Hi Stephen,I've grid like following <igGrid:XamWebGrid x:Name="g" AutoGenerateColumns="False" IsAlternateRowsEnabled="true" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible"> <igGrid:XamWebGrid.Columns> <igGrid:TextColumn Key="Col1"> <igGrid:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text=" Col1"/> </DataTemplate> </igGrid:TextColumn.HeaderTemplate> </igGrid:TextColumn> <igGrid:TextColumn Key=" Col2"> <igGrid:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text=" Col2"/> </DataTemplate> </igGrid:TextColumn.HeaderTemplate> </igGrid:TextColumn> </igGrid:XamWebGrid.Columns> <igGrid:XamWebGrid.CellStyle> <Style TargetType="igGrid:CellControl"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> </Style> </igGrid:XamWebGrid.CellStyle>
</igGrid:XamWebGrid>
this style is applied on button click:
s.Setters.Add(new Setter(CellControl.HorizontalAlignmentProperty, HorizontalAlignment.Center));
it make cell control center align instead of text.
Can you please help me to reolve this issue?
Thanks
You can use the HorizontalContentAlignment property on your Column to control the HorizontalAlignment of a cell's content.
Hi Stephen,
I used following code on column and it works fine for the complete column, but I want to apply Different Alignment on individual cells of a column.
<igGrid:TextColumn Key="Col1" HorizontalContentAlignment="Center"> <igGrid:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="Col1"/> </DataTemplate> </igGrid:TextColumn.HeaderTemplate> </igGrid:TextColumn>
Is there any way to apply different cell alignment in a single column like conditional formating demo example (that applied different cell format on individual cells).
Currently, no.
By having that property, we override the cell's HorizontalAlignment property, so it's not possible to change via a style.
We can look into possibly making the HorizontalContentAlignment property nullable, so that if not specified we respect it on a cell level.
However, i am curious about your use case, of having different cells in the same column aligned differently. Could you explain what you're trying to do?
Thanks,
Hi SteveZ,
It is very old thread, but I am posting on it again, We are again in same situation, where a user wants to align different cells in same column, we have used following code but it makes the controls containg data to be aligned instead of data you can view this in attached image
new Setter(CellControl.HorizontalAlignmentProperty, HorizontalAlignment
.Left));
and
new Setter(CellControl.HorizontalContentAlignmentProperty, null));
new Setter(CellControl.HorizontalAlignmentProperty, HorizontalAlignment.Center));
on the other hand following code have no effect at all:
cell.Style = s;
Can you help me out if this feature hass been fixed in new versions or not at the moment we are using 2011.1