WPF: как определить коллекции для использования в XAML

StackOverflow https://stackoverflow.com/questions/2918956

  •  04-10-2019
  •  | 
  •  

Вопрос

Я хочу определить что-то вроде этого

<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));
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top