views:

2040

answers:

3

That's not a secret: Silverlight's DataGrid default style is beautiful while WPF's is poor.

Instead of reinventing the wheel let me ask the community if anyone has copied the SL styles to use in WPF.

Silverlight default-style DataGrid:
Silverlight DataGrid

WPF default-style DataGrid (updated after Saied K's answer):
WPF DataGrid

+4  A: 

Seems there is not out-the-box style.
I posted a suggestion to Microsoft Connect, please vote.

Anyone who has mimicked the Silverlight DataGrid default style to WPF should please post his answer and I will mark it as answer and give him a vote!

Another closed connection: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=522173.

Thanks a lot!

Shimmy
I voted and added a snarky comment :)
DanM
I saw it, thanks, I hope someone of the lazy employees overthere is going to see it.
Shimmy
I opened a new one, I think once they close a connection, no alerts are received for further comments, please look https://connect.microsoft.com/WPF/feedback/ViewFeedback.aspx?FeedbackID=525883.
Shimmy
+1 for that one too. BTW, one thing that does help a little bit for is to turn the grilines off using `GridLinesVisibility="None"`. It still won't be as pretty as the Silverlight version, but those black gridlines are soooo ugly.
DanM
+1  A: 

Hi,

WPF ships with a number of styles such as Luna, Aero, Classic, etc. These themes are applied based on your system settings. The screenshot from the previous post looks like the WPF Classic theme, but I'm guessing you're looking for a more appealing theme.

If you’re using a Classic system theme on your OS but would like your WPF application to use the Aero theme for example, you can add a merged dictionary to your app and force the Aero theme as shown below. Please note that you may need to change the binary version and public key accordingly.

<Application.Resources>
   <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
         <ResourceDictionary
             Source="/PresentationFramework.Aero;V4.0.0.0;31bf3856ad364e35;component\themes/aero.normalcolor.xaml"/>
      </ResourceDictionary.MergedDictionaries>
   </ResourceDictionary>
</Application.Resources>

Hope that helps, Saied K.

Saied K
I updated my photo, in the new photo you can see the wpf DataGrid's default style in a Windows 7 Aero theme environment, you can clearly see it on the window frame.With all due respect, you really didn't understood my question.
Shimmy
A: 

I voted for both of the connect site bugs too, this really should follow the system theme properly by default!

However in the mean time I found a useful post by Malav Dhalgara which includes the following example that can be used to enable Aero theme's for controls in the WPFToolkit. Assuming from the date that Shimmy posted this question that this example wasn't comming from the DataGrid in .NET 4.0 but I could be wrong and maybe it was from one of the beta's or RCs. Anyway here is one example workaround for those using the WPFToolkit.

        <ResourceDictionary >
            <ResourceDictionary.MergedDictionaries>

                <!--Enable Aero Theme-->
                <ResourceDictionary source="/PresentationFramework.Aero,Version=3.0.0.0,Culture=neutral,
                                             PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;
                                             component/themes/aero.normalcolor.xaml" />

                <ResourceDictionary xmlns:tk="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"
                                             xmlns:sys="clr-namespace:System;assembly=mscorlib">

                    <!--Enable aero theme on toolkit components-->
                    <sys:String x:Key="{ComponentResourceKey 
                                                 TypeInTargetAssembly={x:Type tk:Calendar},ResourceId=Theme}">
                                                 Aero.NormalColor</sys:String>

                    <sys:String x:Key="{ComponentResourceKey
                                                 TypeInTargetAssembly={x:Type tk:DataGrid},ResourceId=Theme}">
                                                 Aero.NormalColor</sys:String>

                    <sys:String x:Key="{ComponentResourceKey
                                                 TypeInTargetAssembly={x:Type tk:DatePicker},ResourceId=Theme}">
                                                 Aero.NormalColor</sys:String>

               </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
jpierson