Home Forums WPF controls Xceed DataGrid for WPF changing cell content text alignment

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25939 |

    Hi group, sorry for the really dumb question, but I cannot find a clear example about this: what’s the easiest way of changing text alignment in a specific data cell? I’d like to use the default templates for both display and edit, and just change text alignment (all cells just have a text content). I suppose I should create a style like:

    <Style x:Name=”centeredCell” TargetType=”{x:Type xcdg:DataCell}”>
    <Setter Property=”HorizontalContentAlignment” Value=”Center”/>
    </Style>

    etc for other alignments, but then how can I specify in XAML that this style must be applied to a SPECIFIC column? All the samples I’ve found just change the style for the whole target type, while I’d like to have a simple data grid like:

    <xcdg:DataGridControl AutoCreateColumns=”False”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”DummyField1″ Title=”one” Width=”50″ />
    <xcdg:Column FieldName=”DummyField2″ Title=”two” Width=”50″ />
    <xcdg:Column FieldName=”DummyField3″ Title=”three” Width=”50″ />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    where DummyField1 text contents should be aligned left, DummyField2 text should be aligned centered, and DummyField3 text should be aligned right. Given that I create 3 named styles for these alignments, what’s the XAML code to tell each column to use a different style for its data cells?

    Imported from legacy forums. Posted by Mathetes (had 3043 views)

    Xceed Support
    Member
    Post count: 5658

    You can use the CellContentTemplate property of a column to change how the content of a cell is displayed or you can add a trigger to your style that only applies the style to the DataCells that have a specific fieldname/parent column.

    We currently have a feature request to add a CellStyle property.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 253 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you, so by now I’ll go with something like (maybe this can be useful to some other reader):

    <xcdg:Column FieldName=”MyField” Title=”a right-aligned cell” Width=”250″>
    <xcdg:Column.CellContentTemplate>
    <DataTemplate>
    <TextBlock Text=”{Binding}” TextAlignment=”Right”/>
    </DataTemplate>
    </xcdg:Column.CellContentTemplate>
    </xcdg:Column>

    Do you have any hint on new version release date? We’d like to purchase a subscription as soon as most of the requested features come out…
    Thanks!

    Imported from legacy forums. Posted by Mathetes (had 550 views)

    Xceed Support
    Member
    Post count: 5658

    We are putting the final touches on version 2.0 and it <b>should</b> be released sometime next month.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 4153 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.