题
我想定义这样的东西
<myCustomControl>
<myCustomControl.Images>
<Image
Source="{StaticResource LockedIcon16}" />
<Image
Source="{StaticResource UnlockedIcon16}"/>
<myCustomControl.Images>
<myCustomControl/>
我需要哪些属性定义才能使该集合(图像)发生?
解决方案
System.Windows.Controls.Image
应该这样做。
尚未测试,但应该起作用。
public class myCustomControl {
//...
public ObservableCollection<Image> Images {
get { return (ObservableCollection<Image>)GetValue(ImagesProperty); }
set { SetValue(ImagesProperty, value); }
}
// Using a DependencyProperty as the backing store for Images. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ImagesProperty =
DependencyProperty.Register("Images", typeof(ObservableCollection<Image>), typeof(myCustomControl), new PropertyMetadata(null));
}
不隶属于 StackOverflow