开发者

WPF: collection DependencyProperty can't "Add" statics

I craeted a dependency property that is an array of dependency properties. I would like to add values in xaml in this way:

<z:Zoomable.UnScale>
                <x:Static Member="Rectangle.StrokeThicknessProperty" ></x:Static>
                <x:Static Member="Ellipse.StrokeThicknessProper开发者_JS百科ty"></x:Static>
</z:Zoomable.UnScale>

but it complains with this error: 'StrokeThickness' is not a valid value for property 'UnScale'.

The property is defined in this way:

public static readonly DependencyProperty UnScaleProperty =
            DependencyProperty.RegisterAttached("UnScale", typeof(ObservableCollection<DependencyProperty>), typeof(Zoomable), new UIPropertyMetadata(GetPropertyCollection(), new PropertyChangedCallback(OnUnscaledChanged)));

I suspect there is some problem in using the StaticExtension, because if I try to add a DepenedencyPropery in pure xaml it works ( although it does not work because there is not empty constructor ). Another odd thing: if I declare the property as an observable collection of object and I add a dummy object in the first place it works! ie:

<z:Zoomable.UnScale>
                <Button> Any object here </Button>
                <x:Static Member="Rectangle.StrokeThicknessProperty" ></x:Static>
                <x:Static Member="Ellipse.StrokeThicknessProperty"></x:Static>
</z:Zoomable.UnScale>


It tries to SET the property to given object instead of adding items to the collection. So, you should be doing something like this:

<z:Zoomable.UnScale>
   <z:DependencyPropertyCollection>
          <x:Static Member="Rectangle.StrokeThicknessProperty" ></x:Static>
          <x:Static Member="Ellipse.StrokeThicknessProperty"></x:Static>
   </z:DependencyPropertyCollection>
</z:Zoomable.UnScale>

Where z:DependencyPropertyCollection is:

public class DependencyPropertyCollection : ObservableCollection<DependencyProperty>
{
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜