WPF: Wie Sammlungen für die Verwendung in XAML definieren
-
04-10-2019 - |
Frage
Ich möchte so etwas wie dieses
definieren,<myCustomControl>
<myCustomControl.Images>
<Image
Source="{StaticResource LockedIcon16}" />
<Image
Source="{StaticResource UnlockedIcon16}"/>
<myCustomControl.Images>
<myCustomControl/>
, welche Eigenschaftsdefinitionen brauch ich diese Sammlung bekommen (Bilder) passiert?
Lösung
System.Windows.Controls.Image
sollte es tun.
Haben Sie nicht getestet, aber es sollte funktionieren.
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));
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow