WPF: cómo definir colecciones para su uso en xaml
-
04-10-2019 - |
Pregunta
quiero definir algo como esto
<myCustomControl>
<myCustomControl.Images>
<Image
Source="{StaticResource LockedIcon16}" />
<Image
Source="{StaticResource UnlockedIcon16}"/>
<myCustomControl.Images>
<myCustomControl/>
¿Qué definiciones propiedad, no tengo que conseguir que la recogida (Imágenes) pasando?
Solución
System.Windows.Controls.Image
debe hacerlo.
¿Es que no lo probó, pero debería funcionar.
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));
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow