小编And*_*nko的帖子

如何在UWP中为集合类型定义`DependencyProperty?

我正在尝试创建一个DependencyObject从Xaml创建的.它 DependencyProperty的类型List<object>定义如下:

    public List<object> Map
    {
        get { return (List<object>)GetValue(MapProperty); }
        set { SetValue(MapProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Map.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty MapProperty =
        DependencyProperty.Register("Map", typeof(List<object>), typeof(MyConverter), new PropertyMetadata(null));
Run Code Online (Sandbox Code Playgroud)

XAML:

        <MyConverter x:Key="myConverter">
            <MyConverter.Map>
                <TextPair First="App.Blank" Second ="App.BlankViewModel"/>
            </MyConverter.Map>
        </MyConverter>
Run Code Online (Sandbox Code Playgroud)

我一直在接受Cannot add instance of type 'UwpApp.Xaml.TextPair' to a collection of type 'System.Collections.Generic.List<Object>.什么可能导致此错误?谢谢.

4
推荐指数
1
解决办法
1452
查看次数

标签 统计