如何解决可观察的项目集合不会触发转换器
我有一个这样的 xaml(我删除了无用的行)
<Window x:Class="LaRenouvellerieUpdater.MainWindow"
xmlns:converters="clr-namespace:LaRenouvellerieUpdater.Converters">
<Window.Resources>
<ResourceDictionary>
<viewmodel:DataViewModel x:Key="DataViewModel"/>
<model:PhotosModel x:Key="PhotosModel"/>
<converters:UriToCachedImageConverter x:Key="UriToCachedImageConverter"/>
</ResourceDictionary>
</Window.Resources>
<Grid>
<TabControl>
<TabItem Header="Posts instagrams">
<DataGrid ItemsSource="{Binding InstagramsPhotos,Mode=TwoWay}"
DataContext="{Binding Source={StaticResource DataViewModel}}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Url" Width="*" MaxWidth="150">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding Path=Url,Converter={StaticResource UriToCachedImageConverter},Mode=TwoWay}" DecodePixelWidth="150" />
</Image.Source>
</Image>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
还有一个像这样的可观察集合:
private ObservableCollection<PhotosModel> _instagramsPhotos = new ObservableCollection<PhotosModel>();
public ObservableCollection<PhotosModel> InstagramsPhotos
{
get => _instagramsPhotos;
set
{
_instagramsPhotos = value;
RaisePropertyChanged();
}
}
像这样的照片模型:
public PhotosModel(Action<object,PropertyChangedEventArgs> photosModel_PropertyChanged)
{
PropertyChanged = new PropertyChangedEventHandler(photosModel_PropertyChanged);
}
private void NotifyPropertyChanged([CallerMemberName] string name = "") =>
PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(name));
private string _url;
public string Url
{
get => _url;
set
{
_url = value;
NotifyPropertyChanged("Url");
}
}
当我在 observablecollection 中推送元素时,我的 Converter UriToCachedImage 永远不会在开始时触发。我不知道为什么。 我尝试将我的 observable 集合传递给所有 PhotosModel 以在属性被修改但不起作用时触发它。
谢谢
解决方法
我通过在我的类中创建一个执行转换器工作的属性来解决这个问题。这不是我想要的,但它确实有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。