动态设置 Silverlight DataGrid 列的标题文本 [英] Dynamically setting the Header text of a Silverlight DataGrid Column

查看:24
本文介绍了动态设置 Silverlight DataGrid 列的标题文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  <my:DataGridTemplateColumn 
            CanUserResize="False" 
            Width="150" 
            Header="{Binding MeetingName, Source={StaticResource LocStrings}}" 
            SortMemberPath="MeetingName"> 
  </my:DataGridTemplateColumn>

我在 Silverlight 网格控件中有上述列.但是由于我尝试设置 Header 属性的方式,它给了我一个 XamlParser 错误.以前有人这样做过吗?我想为多种语言执行此操作.

I have the above column in a Silverlight grid control. But it is giving me a XamlParser error because of how I am trying to set the Header property. Has anyone done this before? I want to do this for multiple languages.

另外,我绑定到资源的语法是正确的,因为我在网格外的标签中尝试过.

Also my syntax for the binding to a resouce is correct because I tried it in a lable outside of the grid.

推荐答案

您不能绑定到 Header,因为它不是 FrameworkElement.您可以通过像这样修改标题模板来使文本动态化:

You can't Bind to Header because it's not a FrameworkElement. You can make the text dynamic by modifying the Header Template like this:

xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

<data:DataGridTemplateColumn>   
   <data:DataGridTemplateColumn.HeaderStyle>
       <Style TargetType="dataprimitives:DataGridColumnHeader">
          <Setter Property="Template">
             <Setter.Value>
                <ControlTemplate>                                        
                  <TextBlock Text="{Binding MeetingName, Source={StaticResource LocStrings}}" />                
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
   </data:DataGridTemplateColumn.HeaderStyle>
</data:DataGridTemplateColumn>

这篇关于动态设置 Silverlight DataGrid 列的标题文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆