首页 > 解决方案 > 如何在 WPF 中创建字符串列表的依赖属性?

问题描述

我找到了一些例子,但似乎没有一个有效。我正在尝试通过此依赖属性将字符串列表绑定到我的用户控件。

public IList ImageNames
    {
        get { return (IList)GetValue(ImageNamesProperty); }
        set { SetValue(ImageNamesProperty, value); }
    }

// Using a DependencyProperty as the backing store for ImageNames.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty ImageNamesProperty =
    DependencyProperty.Register("ImageNames", typeof(IList), typeof(DynamicWallpaperUserControl), new PropertyMetadata(new List<string>()));

在 ViewModel 中,我有一个 List String DesertImages,我将它绑定到用户控件。在 Xaml 中:

 <controls:DynamicWallpaperUserControl
           Background="Transparent"
           ImageNames="{Binding Path=DesertImages}" />

Visual Studio 说列表是空的,尽管感谢任何帮助

标签: wpfdependency-properties

解决方案


推荐阅读