Question: How do I bind StatName.Width
to Samp1.ActualWidth + Samp2.ActualWidth
?
Sub-questions:<
The code finally executes as expected with the following:
<Binding Source="{x:Reference Samp2}" Path="ActualWidth" />
return new DataGridLength(totalWidth);
The Converter
gets called on load and when resizing Samp1
or Samp2
. The column widths remain synchronized as expected.
<DataGridTextColumn x:Name="StatName" Binding="{Binding a}" Header="Stat">
<DataGridTextColumn.Width >
<MultiBinding Converter="{StaticResource WidthConverter}">
<Binding Source="{x:Reference Samp1}" Path="ActualWidth" />
<Binding Source="{x:Reference Samp2}" Path="ActualWidth" />
</MultiBinding>
</DataGridTextColumn.Width>
</DataGridTextColumn>
The Convert
function needed to return a DataGridLength
, the data type of DataGridTextColumn.Width
.
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double totalWidth = 0;
foreach (double Width in values)
totalWidth += Width;
return new DataGridLength(totalWidth);
}
Note: The code executes as expected, regardless of the error Specified cast is not valid.
<MultiBinding ... </MultiBinding>
in cyan.