WPF DataGrid style-Silverlight DataGrid?
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 style开发者_运维知识库s to use in WPF.
Please take a look at the screenshots and judge for yourself how the Silverlight and WPF teams invest in their products.
Silverlight default-style DataGrid:
WPF default-style DataGrid (updated after Saied K's answer):
I haven't found any projects with a working Silverlight-style DataGrid
, so I created one on Codeplex:
http://datagridthemesfromsl.codeplex.com
Doesn't have all the themes, but there's at least a few there.
Buried deep within MSDN, I found this.
Toward the bottom of the article, you will see this phrase:
For example, take a look at the following illustration that shows part of the Styling with ControlTemplates Sample
If you click 'Styling with ControlTemplates Sample', it will take you to a download link. After download, you can compile the project and it includes all kinds of styles, including the elusive datagrid style! You can take MS's DataGrid.xaml file and modify it for your needs.
Seems there is not out-the-box style.
I posted a suggestion to Microsoft suggestions site, please vote here and here!!!
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!
Thanks a lot!
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.
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>
精彩评论