UWP怎么打开图片
UWP这玩意水有点深啊,我用Source设置了一个图片的绝对路劲,用代码无法看到图片,用数据绑定也无法看到图片。
xaml在这里:
<ListView x:Name="listView"
HorizontalAlignment="Left"
Height="650" Margin="235,200,0,0" VerticalAlignment="Top" Width="1220" ItemsSource="{x:Bind Item,Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate >
<Grid>
<Image Source="{Binding Source}"/>
<TextBlock Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
数据模型在这:
public class Item : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
public string Name
{
get
{
return _name;
}
set
{
_name = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
}
}
private string _img;
public string Img
{
get
{
return _img;
}
set
{
_img = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Img"));
}
}
}
在View层里面也就是MainPage里面我只是添加了一个ObservableCollection<Item> Item的属性,图片控件的ImageSource绑定到Item,现在是图片无法显示,但是Name属性的绑定已经可以看到结果了