styling differences between WPFToolkit datagrid and System.Windows.Controls.Data (silverlight) datagrid

Sep 29, 2008 at 3:57 PM
Edited Sep 29, 2008 at 3:58 PM
Hi,
I'm working on the migration of a silverlight project to WPF.
I've changed the use of silverlight's datagrid (xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data") to xmlns:data="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"

The problem is that the styling used in the Silverlight version do not work "as is" : the grid content seems empty when i define the styling.
Is there some differences i should be aware of, so that the styling can work ?
Thanks,


Example :

<

 

data:DataGrid x:Name="dgBookings" Grid.Row="4" Foreground="DarkOrange" AutoGenerateColumns="False" Height="Auto" Width="Auto"
MinWidth="1063" Background="Black" BorderBrush="DarkBlue" ClipToBounds="False" HorizontalScrollBarVisibility="Hidden"
Style="{StaticResource BaseStyle}"
ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"
RowHeaderStyle="{StaticResource RowHeaderStyle}"
RowStyle="{StaticResource RowStyle}" >

 

Coordinator
Sep 29, 2008 at 6:06 PM
Could you supply the snippets of the styles that are not working and what about them that aren't working.
Oct 3, 2008 at 9:39 AM
Thanks,

I used the following style. In the silverlight version, the grid is ok, i can see rows inside, and data. In the wpf version, the grid is dark grey everywhere, and no data is visible, as if it was empty (but a break point in the code confirms that the data is here). When i remove the style from the WPF version, i can see the rows back.



        <!--Base DataGrid Style-->
        <Style x:Key="BaseStyle" TargetType="data:DataGrid">
            <Setter Property="Background" Value="{StaticResource BaseColorBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource BaseColorBrush}"/>
            <Setter Property="RowBackground">
                <Setter.Value>
                    <SolidColorBrush Color="#00000000"/>
                </Setter.Value>
            </Setter>
            <Setter Property="AlternatingRowBackground">
                <Setter.Value>
                    <SolidColorBrush Color="#00000000"/>
                </Setter.Value>
            </Setter>
            <Setter Property="HorizontalGridLinesBrush">
                <Setter.Value>
                    <SolidColorBrush Color="#00000000"/>
                </Setter.Value>
            </Setter>
            <Setter Property="VerticalGridLinesBrush">
                <Setter.Value>
                    <SolidColorBrush Color="#00000000"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="data:DataGrid">
                        <Grid x:Name="Parent">
                            <Border CornerRadius="2" Background="#FFFFFFFF"/>
                            <Border CornerRadius="2" Background="{TemplateBinding Background}" Opacity="0.9"/>
                            <Grid Name="RootElement" Margin="4">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <!-- Row 0 -->
                                <data:DataGridColumnHeadersPresenter Background="{TemplateBinding Background}" Name="ColumnHeadersPresenterElement" Grid.Column="0" Grid.Row="0"/>

                                <!-- Row 1 -->
                                <data:DataGridRowsPresenter Name="RowsPresenterElement" Grid.Column="0" Grid.Row="1" />
                                <ScrollBar Background="{TemplateBinding Background}" Style="{StaticResource ScrollBarStyle}" Name="VerticalScrollbarElement" Orientation="Vertical" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Width="14" Margin="4,0,0,0" />

                                <!-- Row 2  -->
                                <ScrollBar Background="{TemplateBinding Background}" Style="{StaticResource ScrollBarStyle}" Name="HorizontalScrollbarElement" Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="2" Height="14" />
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Coordinator
Oct 3, 2008 at 2:40 PM
In the Silverlight DataGrid there is an incompatible scrolling issue where it cannot use a ScrollViewer.  Since the WPF DataGrid does use a ScrollViewer, the templates are slightly incompatible and changes would have to be made to the template to have it work for both.  If you take a look at the generic.xaml file in the CTP source you can see what the default WPF DataGrid template looks like.