In my application I created templated control. Now I want to bind MinWidth to dependency property. For example in my xaml I have
<ColumnDefinition Width="Auto" MinWidth="{TemplateBinding ColumnWidth}"/>
and in my code
public double ColumnWidth
{
get { return (double)GetValue(ColumnWidthProperty); }
set { SetValue(ColumnWidthProperty, value); }
}
public static readonly DependencyProperty ColumnWidthProperty =
DependencyProperty.Register(
"ColumnWidth", typeof(double), typeof(Schedule), new PropertyMetadata(200));
Unfortunately, it doesn't work and I dont know why. MinWidth is always 0. Maybe someone knows what I'm doing wrong ?
I don't know why the TemplateBinding
won't work in your case, but you could always replace it by a regular Binding
like this:
<ColumnDefinition MinWidth="{Binding ColumnWidth,
RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
I've tested this in a ControlTemplate of a custom control. TemplateBinding
doesn't work, Binding
does.