WPF DataGrid style-Silverlight DataGrid?

两盒软妹~` 提交于 2019-11-28 21:16:09
T. Webster

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.

Matt

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!

Saied K

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!