开发者

Binding DataGridHeader ContentTemplate in Silverlight

I know that its not implicitly possible to bind text to a DataGrid header via Dynamically setting the Header text of a Silverlight DataGrid Column, but I was following some code examples online to substitute a TextBlock for the header. However, no matter what I do the text that I've bound to won't show up.

My XML from my view:

<dg:DataGridTextColumn Binding="{Binding Path=UnitKey}" IsReadOnly="True">
 <dg:DataGridTextColumn.HeaderStyle>
  <Style TargetType="dataprimitives:DataGridColumnHeader">
   <Setter Property="ContentTemplate">
    <Setter.Value>
    <开发者_如何学JAVADataTemplate>
      <TextBlock Text="{Binding Path=KeyListName}"/>
    </DataTemplate>
    </Setter.Value>
   </Setter>
  </Style>
 </dg:DataGridTextColumn.HeaderStyle>
</dg:DataGridTextColumn>

My C# from my View Model:

    public string KeyListName
    {
        get { return keyListName; }
        set
        {
            keyListName = value;
            raisePropertyChanged("KeyListName");
        }
    }

I can't figure out what I overlooked.. Thanks in advance for your help!


put a datacontext in your TextBlock

 <TextBlock DataContext="" Text="{Binding Path=KeyListName}"/>

OR

If they have the same datacontext with your UnitKey

<dg:DataGridTextColumn x:Name="dgColumnUnit" Binding="{Binding Path=UnitKey}" IsReadOnly="True">

The reason why its not binding because the parent which is your DataGridTextColumn has been binded already, try to debug it and take a look at your Output window it will prompt that KeyListName cannot be found ....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜