0

在我的应用程序中,我创建了模板控件。现在我想将 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。也许有人知道我做错了什么?

4

1 回答 1

1

我不知道为什么TemplateBinding在你的情况下不起作用,但你总是可以用这样的常规替换它Binding

<ColumnDefinition MinWidth="{Binding ColumnWidth,
                             RelativeSource={RelativeSource Mode=TemplatedParent}}"/>

我已经在自定义控件的 ControlTemplate 中对此进行了测试。TemplateBinding行不通,Binding行。

于 2013-04-13T17:50:27.233 回答