C# WPF将未知数量的字符串传递给用户控件
好的,我有一个用户控件,它有一个图像url属性C# WPF将未知数量的字符串传递给用户控件,c#,wpf,xaml,user-controls,C#,Wpf,Xaml,User Controls,好的,我有一个用户控件,它有一个图像url属性 public static readonly DependencyProperty ImageUrlProperty = DependencyProperty.Register("ImageUrl", typeof(string), typeof(CoreGameTile)); public string ImageUrl { get { return (string)GetValue(ImageUrlPro
public static readonly DependencyProperty ImageUrlProperty = DependencyProperty.Register("ImageUrl", typeof(string), typeof(CoreGameTile));
public string ImageUrl
{
get { return (string)GetValue(ImageUrlProperty); }
set { SetValue(ImageUrlProperty, value); }
}
现在我如何在不知道确切数字的情况下传递多个图像URL呢
因此,有时我会有5个图像URL,其他时候我可能有2个左右。在不知道确切数量的情况下传递多个图像URL的方法是什么
我还希望能够使用XAML像这样添加它
<Controls:CoreGameTile Width="200" Height="100" Margin="2" Title="Bink" ImageUrl="http://www.splashdamage.com/screens_brink/031.jpg"/>
也许您可以将
图像URL
的列表传递给它,您可以使用foreach
循环来设置列表中的每个图像URL
public string ImageUrl
{
get { return (List<string>)GetValue(ImageUrlProperty); }
set
{
foreach (ImageUrl url in value)
{
SetValue(ImageUrlProperty, url);
}
}
}
公共字符串ImageUrl
{
get{return(List)GetValue(ImageUrlProperty);}
设置
{
foreach(值为ImageUrl的url)
{
SetValue(ImageUrlProperty,url);
}
}
}
Agree的可能副本。将typeof(字符串)
更改为typeof(列表)
。