我做错了什么?
的Xaml:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="26*"/>
<RowDefinition Height="63*"/>
<RowDefinition Height="67*"/>
</Grid.RowDefinitions>
<TextBlock Name ="title" Text="" TextWrapping="NoWrap" Grid.Row="0" Margin="25,10,25,0"/>
<Image Source="{Binding Path=BindImgURL}" HorizontalAlignment="Left" Height="164" Grid.Row="1" VerticalAlignment="Top" Width="306" Margin="152,0,0,0"/>
</Grid>
C#代码:
private string Id;
private string ImgURL;
public VideoDetails(string Id)
{
InitializeComponent();
this.Id = Id;
DetailsGenerator dg = new DetailsGenerator(Id);
this.ImgURL = "Dynamic source";
this.DataContext = BindImgURL;
MessageBox.Show(BindImgURL);
}
public string BindImgURL
{
get { return ImgURL; }
set
{ ImgURL = value; }
}
显示来源正确! 由MessageBox.But检查没有图像 我做错了什么?我试过删除&#34; path =&#34;但是没有工作
答案 0 :(得分:1)
我想你要么将DataContext
设置为this
this.DataContext = this;
或更改绑定到当前DataContext
<Image Source="{Binding}" .../>
目前Image
会在当前BindImgURL
中搜索DataContext
,该BindImgURL
设置为string
且PropertyChanged
与您的问题无关,但我建议您在设置BindImgURL
之后,考虑实施INotifyPropertyChanged
并为DataContext
举办BindImgURL
次活动UI