Cannot serialize a generic type 'System.Windows.FreezableCollection`

前端 未结 1 1831
天命终不由人
天命终不由人 2021-01-24 03:35

Hopefully a simple question. I have a custom control with a dependency property that contains a list of another custom control.

public static readonly Dependenc         


        
相关标签:
1条回答
  • 2021-01-24 04:20

    Ok Silly me there is alot of information about this all over the net, the simple solution is to take the generic freezablecollection and derive a none generic class as below.

    public class BlockObjectCollection : FreezableCollection<BlockObject>
    {
    }
    

    then replace the dependency properties

        public static readonly DependencyProperty BlockObjectsProperty = DependencyProperty.Register("BlockObjects", typeof(BlockObjectCollection), typeof(Block), new FrameworkPropertyMetadata(new BlockObjectCollection(), null));
        public BlockObjectCollection BlockObjects
        {
            get { return (BlockObjectCollection)base.GetValue(BlockObjectsProperty); }
            set { base.SetValue(BlockObjectsProperty, value); }
        }
    
    0 讨论(0)
提交回复
热议问题