首页 > 代码库 > WPF 依赖熟悉使用

WPF 依赖熟悉使用

1,在XML中绑定

xmlns:toolbox="clr-namespace:EBookApp.Toolbox"

<Image x:Name="imageShort" Stretch="Fill" Width="50" d:LayoutOverrides="HorizontalMargin"
                       Source="{Binding RelativeSource={RelativeSource AncestorType=toolbox:ResDetailItemControl},Path=Thumbnail}"/>

2,在cs文件中定义

public static readonly DependencyProperty ThumbnailProperty =
            DependencyProperty.Register("Thumbnail", typeof(string), typeof(ResDetailItemControl), new PropertyMetadata("../Images/img.png"));

        public string Thumbnail
        {
            get { return (string)GetValue(ThumbnailProperty); }
            set { SetValue(ThumbnailProperty, value); }
        }


WPF 依赖熟悉使用