我的任务是根据包含在的数据网格的列设置Expander的TextBlock宽度.XAML是这样的:
<DataGrid x:Name="GridData" Grid.Column="4" Height="287" ColumnWidth="Auto" CanUserResizeColumns="False">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander Background="Red" HorizontalAlignment="Left" HorizontalContentAlignment="Left">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Width="{Binding ElementName=GridData.colTimeAlarm, Path=ActualWidth}" Background="Azure" Text="{Binding StringFormat=hh\\:mm\\:ss, Converter={StaticResource SumTimes}, ConverterParameter=TimeAlarm}" />
</StackPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" MinWidth="80" Binding="{Binding Data, UpdateSourceTrigger=PropertyChanged}" Header="@_151_Data" Foreground="Black" IsReadOnly="True" x:Name="colTimeAlarm" />
</DataGrid.Columns>
在TextBlock中,我将width属性绑定为指定列的ActualWidth,但它不起作用。怎么了?