Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>At first glance, your code is normal, should work. But when your dependency property is set to <code>DataGridTextColumn</code>, <code>SetUnit</code> not called and the variable <code>Unit</code> value <code>NULL</code>. I tried to assign a value of attached dependency property in <code>Window</code> (since it attached, you can set its value anywhere) in this case must work:</p> <pre><code>&lt;Window x:Class="DataGridAttachedHelp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:DataGridAttachedHelp" local:CustomHeader.Unit="[m/s]" Name="MyWindow" Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen"&gt; &lt;Grid&gt; &lt;DataGrid x:Name="tObjectDataGrid" Margin="10,50,10,10" AutoGenerateColumns="False" EnableRowVirtualization="True" RowDetailsVisibilityMode="VisibleWhenSelected" &gt; &lt;DataGrid.Resources&gt; &lt;DataTemplate x:Key="CustomHeaderTemplate"&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding}" /&gt; &lt;TextBlock Text="{Binding Path=(local:CustomHeader.Unit), ElementName=MyWindow}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/DataGrid.Resources&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn x:Name="SpeedColumn" Width="1*" Binding="{Binding Speed}" Header="Speed" HeaderTemplate="{StaticResource CustomHeaderTemplate}" /&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>In your case the property did not work, because it is necessary to indicate the source of the properties, for example: <code>ElementName</code>, <code>Source</code>. Therefore, simply add the name of <code>DataGridTextColumn</code> in parameter <code>ElementName</code>:</p> <pre><code>&lt;TextBlock Text="{Binding Path=(local:CustomHeader.Unit), ElementName=SpeedColumn}" /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload