The wpf application has a problem updating data from the code for the View

xellan 20 Баллы репутации
2024-03-04T11:22:21.2833333+00:00

I have a View Model for a Wpf application

public class ProductVM: ViewModelBase, IProductVM
 {
     public ProductVM(IProductModel Repository)
     {
         this.Repository = Repository;
         ProductDataList = Repository.ProductCollections;
         if(ProductDataList.Count() > 0)
         Selected = ProductDataList[0];
     }
     public IReadOnlyObservableCollection<IProduct> ProductDataList { get => Get<IReadOnlyObservableCollection<IProduct>>(); set => Set(value); }


     IProductModel Repository { get; set; }

     public IProduct Selected { get => Get<IProduct>(); set => Set(value); }
	 
	  
	  private ICommand _Add;
      public ICommand Add => _Add ?? new RelayCommand(AddExcute);
      
	  private void AddExcute()
 {
     Selected.Name = "RRRRRRRRRRRRRRRR";

 }
}

I get the data for the Product Data List like this

public IReadOnlyObservableCollection<TTarget> ToObservableCollections()
  {
      set.Load();
      IReadOnlyObservableCollection<TTarget>? collection;
      var list = set.Local.ToObservableCollection();
      collection = new ReadOnlyObservableList<TTarget, TSource>(list);
      return collection;
  }
  

If I make changes to the View in Selected it is displayed. But I don't understand how I can make changes from the code appear in the View when calling the Add command, tell me what I can do or what to use

Just in case, I'll indicate how I use the binding

<ListBox x:Name="LbProduct"
        Grid.Column="1" 
        Margin="1 0 0 0"
        ItemsSource="{Binding ProductDataList}"
        SelectedItem="{Binding Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
   <ListBox.ItemTemplate>
       <DataTemplate DataType="{x:Type model:IProduct}">
           <StackPanel>
               <TextBlock Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBlock>
               <TextBlock Margin="0 4 0 0" Text="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBlock>
           </StackPanel>
       </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>
Windows Presentation Foundation
Windows Presentation Foundation
Часть платформа .NET Framework, которая предоставляет единую модель программирования для создания бизнес-классических приложений в Windows.
1 вопрос
Комментариев: 0 Без комментариев
Голосов: {count}

Ответы: 2

Сортировать по: Наиболее полезные
  1. xellan 20 Баллы репутации
    2024-03-04T16:10:00.46+00:00

    The change tracking proxies from this topic solved my problem

    https://learn.microsoft.com/ru-ru/ef/core/change-tracking/change-detection

    Комментариев: 0 Без комментариев

  2. Maksim Marinov (Convergys Corporation) 405 Баллы репутации Поставщик Майкрософт
    2024-03-05T10:46:51.01+00:00

    Hello, This is a Russian speaking Q&A. Would you like to continue working on your issue in Russian? In case you wish to continue in English, you may ask your question on the English Q&A: https://learn.microsoft.com/en-us/answers/

    Комментариев: 0 Без комментариев

Ваш ответ

Автор вопроса может помечать ответы как принятые. Это позволяет пользователям узнать, что ответ помог решить проблему автора.