[英]Why binding to MinWidth doesn't work?
在我的应用程序中,我创建了模板控件。 现在,我想将MinWidth绑定到依赖项属性。 例如在我的xaml中
<ColumnDefinition Width="Auto" MinWidth="{TemplateBinding ColumnWidth}"/>
在我的代码中
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));
不幸的是,它不起作用,我也不知道为什么。 MinWidth始终为0。也许有人知道我在做什么错?
我不知道为什么TemplateBinding
在您的情况下不起作用,但是您总是可以用常规的Binding
替换它,如下所示:
<ColumnDefinition MinWidth="{Binding ColumnWidth,
RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
我已经在自定义控件的ControlTemplate中对此进行了测试。 TemplateBinding
不起作用, Binding
起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.