0

我的 XAML 文件中有以下绑定:

Fill="{Binding ElementName=cpRange1, Path=CurrentColor}"

设置同一建筑物但在执行时间的语法是什么?

4

1 回答 1

1

目前尚不完全清楚您要达到的目标。如果您尝试在运行时在后面的代码中对对象设置绑定,您应该可以这样做:

对于给定的Rectangle

<Rectangle Name="MyRect"/>

在您的代码中:

        // Property to bind (example)....
        public SolidColorBrush MyColor { get; set; }
        //

        // In some initialisation method.
        MyColor = new SolidColorBrush(Colors.Blue);

        Binding myBinding = new Binding("MyColor");
        MyRect.SetBinding(Rectangle.FillProperty, myBinding);

在您的特定情况下,您可能希望设置myBinding.ElementName, 并指向myBinding.Path您希望定位的元素上的属性。

我可能误解了你的目标。

MSDN

于 2013-07-11T15:37:13.273 回答