我想我的XAML页面上的椭圆内的imageSource绑定到我的ViewModel中的ImageSource属性,因为我在我的项目中使用MVVM方法。我可以通过断点来确认c#中的属性获取图像并被填充,但由于某些奇怪的原因,它不会显示在XAML中,并且当我在混合中使用livepropertyExplorer分析源属性时,ImageSource中的源显示“0 ”。这是我的代码。uwp图像绑定不工作与x:绑定
XAML
<Ellipse x:Name="ProfileImage" Style="{StaticResource ProfilePicStyle}">
<Ellipse.Fill>
<ImageBrush ImageSource="{x:Bind ViewModel.Banner, Mode=OneWay}"
Stretch="UniformToFill"/>
</Ellipse.Fill>
</Ellipse>
视图模型
public AllVideosViewModel() : base()
{
//var bit = new BitmapImage();
//bit.UriSource = (new Uri("ms-appx:///Assets/Storelogo.png"));
//Banner = bit;
//Above 3 lines were test code and it works perfect and binding works in this case, but I want the binding as coded in the Initialize method below, because I want that image to bind with the thumbnails of the collection.
Initialize();
}
private async void Initialize()
{
var VideoFiles = (await KnownFolders.VideosLibrary.GetFilesAsync(CommonFileQuery.OrderByName)) as IEnumerable<StorageFile>;
foreach (var file in VideoFiles)
{
<...some code to fill grid view on the same XAML page which works perfect...>
Banner = await FileHelper.GetDisplay(file);//this method returns Image just fine because I am using the same method to display thumbnails on the same XAML page which work fine.
}
}
在此先感谢。
UPDATE示例项目
sample project to test on github
“此方法返回图像...”。实际上,它应该返回一个ImageSource(或像BitmapImage这样的派生类型)。 Banner属性的类型是什么? – Clemens
横幅属性的类型是ImageSource和方法GetDisplay返回BitmapImage – touseef
方法是好的,因为我指定我使用相同的方法来填充我的gridview缩略图在同一页上 – touseef