以下に数値キーに対するイメージのカスタムコントロールを記述する。
    public class SampleContentControl : ContentControl
    {
        public ImageList ImageList
        {
            get { return (ImageList)GetValue(ImageListProperty); }
            set { SetValue(ImageListProperty, value); }
        }
        public static readonly DependencyProperty ImageListProperty =
            DependencyProperty.Register("ImageList", typeof(ImageList), typeof(SampleContentControl), new PropertyMetadata(new ImageList()));
    }
    public class ImageList : List<ImageInfo>
    {
    }
    public class ImageInfo
    {
        public int Key { get; set; }
        public ImageSource Value { get; set; }
    }
XAML 側の定義はこうなる。(ResourceDicitonary内ね)
    <local:ImageList x:Key="imageList">
        <local:ImageInfo Key="1" Value="{StaticResource aaa}"/>
        <local:ImageInfo Key="2" Value="{StaticResource bbb}"/>
        <local:ImageInfo Key="3" Value="{StaticResource ccc}"/>
    </local:ImageList>
0 件のコメント:
コメントを投稿