Silverlight控件DataGrid自定义模板(DataGridTextColumn.ElementStyle)实现居中对齐等复杂界面...

Silverlight的DataGrid是功能不完善,还是这种布局的模式我没有掌握呢?

或许是这样:Silverlight的控件后台处理起来像WinForm,前台布局像WebForm
我想随意控制DataGrid列的宽度,对齐方式等,发现根本没有相关属性,
搜索了半天,发现使用模板的方式可以解决,另外在这里不得不说一下:百度在搜索编程方面的结果,真是太垃圾了。
找代码方面的问题,还是google吧。

ExpandedBlockStart.gif 大气象
< sdk:DataGrid  AutoGenerateColumns ="False"  x:Name ="dgEmployee1"  Margin ="5 55 10 0"  Width ="500"  Height ="160" >
    
< sdk:DataGrid.Columns >
        
< sdk:DataGridTextColumn  Binding =" {Binding 楼层号} "  Header ="楼层号"  Width ="100" >

            
< sdk:DataGridTextColumn.HeaderStyle >
                
< Style  TargetType ="sdk:DataGridColumnHeader" >
                    
< Setter  Property ="Width"  Value ="100" > Setter >
                    
< Setter  Property ="HorizontalContentAlignment"  Value ="Center" > Setter >
                
Style >
            
sdk:DataGridTextColumn.HeaderStyle >

            
< sdk:DataGridTextColumn.ElementStyle >
                
< Style  TargetType ="TextBlock" >
                    
< Setter  Property ="Foreground"  Value ="Red" > Setter >
                    
< Setter  Property ="HorizontalAlignment"  Value ="Center" > Setter >
                
Style >
            
sdk:DataGridTextColumn.ElementStyle >
        
sdk:DataGridTextColumn >
    
sdk:DataGrid.Columns >
sdk:DataGrid >

 参考:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid(VS.95).aspx
http://stackoverflow.com/questions/449386/silverlight-how-do-you-bind-to-control-s-in-the-datagridtextcolumn-headerstyle

你可能感兴趣的:(Silverlight控件DataGrid自定义模板(DataGridTextColumn.ElementStyle)实现居中对齐等复杂界面...)