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); } }