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); } }
时间: 2024-10-14 12:55:59