Sign In|Join
Home/Silverlight.NET Forums/General Silverlight Programming/Programming with .NET - General/Alignment in DataGrid Control
Last post Nov 20, 2008 05:51 AM by Amanda Wang - MSFT
Member
15 Points
163 Posts
Nov 17, 2008 08:48 AM | LINK
Hi In my silverlight Application i am creating DataGrid Columns at runtime as below
textColumn = new DataGridTextColumn(); textColumn.IsReadOnly = true; textColumn.Header = "Current Vehicles Site Enabled"; textColumn.ElementStyle = Resources["AlignCenter"] as Style; //textColumn.CellStyle = Resources["AlignCenter"] as Style; textColumn.Binding = new System.Windows.Data.Binding("CurrentVehicles_SiteEnabled");
I want to add the Horizontal Align to Right. I have tried as below
<Style x:Key="AlignCenter" TargetType="DataGridCell"> <Setter Property="Foreground" Value="Blue"/> <Setter Property="HorizontalContentAlignment" Value="Right"/> </Style>
But still it is not working.
Any help.
I am using Silverlight 2 Release.
Thanks Anandraj.A.
Contributor
4222 Points
864 Posts
Nov 17, 2008 10:47 AM | LINK
you have to set the CellStyle
<
</
Nov 17, 2008 01:56 PM | LINK
Thanks it is working fine.
When I put this code in the Usercontrol then it is working fine, but When move the code to the app.xaml then it is not working. How to make to global so that I can make use of the same in all the pages.
Thanks
Anandraj.A.
All-Star
17236 Points
1466 Posts
Microsoft
Nov 20, 2008 05:51 AM | LINK
Hi,
If you want to refer the styles in the app.xaml, you can use the code like this: App.Current.Resources["AlignCenter"] as Style
If you use this code: Resources["AlignCenter"] as Style; which only can get the locally defined resource.
a_anandraj@h...
Member
15 Points
163 Posts
Alignment in DataGrid Control
Nov 17, 2008 08:48 AM | LINK
Hi
In my silverlight Application i am creating DataGrid Columns at runtime as below
I want to add the Horizontal Align to Right. I have tried as below
But still it is not working.
Any help.
I am using Silverlight 2 Release.
Thanks
Anandraj.A.
lee_sl
Contributor
4222 Points
864 Posts
Re: Alignment in DataGrid Control
Nov 17, 2008 10:47 AM | LINK
you have to set the CellStyle
<
UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SilverlightApplication1.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <UserControl.Resources> <Style x:Key="AlignCenter" TargetType="data:DataGridCell"> <Setter Property="HorizontalContentAlignment" Value="Right" /> </Style> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"><
data:DataGrid Width="400" Height="400" AutoGenerateColumns="False" x:Name="datagrid1"></data:DataGrid> </Grid></
UserControl>Available for consulting in Dallas, TX
http://leeontech.wordpress.com/
a_anandraj@h...
Member
15 Points
163 Posts
Re: Alignment in DataGrid Control
Nov 17, 2008 01:56 PM | LINK
Thanks it is working fine.
When I put this code in the Usercontrol then it is working fine, but When move the code to the app.xaml then it is not working. How to make to global so that I can make use of the same in all the pages.
Thanks
Anandraj.A.
Amanda Wang...
All-Star
17236 Points
1466 Posts
Microsoft
Re: Alignment in DataGrid Control
Nov 20, 2008 05:51 AM | LINK
Hi,
If you want to refer the styles in the app.xaml, you can use the code like this: App.Current.Resources["AlignCenter"] as Style
If you use this code: Resources["AlignCenter"] as Style; which only can get the locally defined resource.
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.