0
<Grid x:Name="ContentGrid">
<Grid.Resources>
<Image x:Key="art" Source="art.png" Stretch="None" />
</Grid.Resources>
<ContentControl Content="{Binding MyImg}" />
</Grid>
public Image MyImg
{
get { return (Image)GetValue(MyImgProperty); }
set { SetValue(MyImgProperty, value); }
}
public static readonly DependencyProperty MyImgProperty =
DependencyProperty.Register("MyImg", typeof(Image), typeof(MainPage), null);
public MainPage()
{
InitializeComponent();
ContentGrid.DataContext = this;
// Works.
MyImg = new Image() { Source = new BitmapImage(new Uri("art.png", UriKind.Relative)), Stretch = Stretch.None };
// Doesn't Work. Exception The parameter is incorrect. ???
MyImg = ContentGrid.Resources["art"] as Image;
}
ContentGrid.Resources [「藝術」]作爲圖片不reuturn空但具有相同的源作爲art.png但分配給依賴屬性的圖像失敗!爲什麼?錯誤從資源字典綁定ContentControl中到圖像