프리즘 WPF를 처음 사용하고 응용 프로그램을 구성하는 방법 및 방법을 처음으로 이해했습니다.OnNavigatedTo 메서드를 사용하여 Combobox 바인딩 빈입니다.
'OnNavigatedTo'메서드를 사용하여보기의 컨트롤에 데이터 바인딩에 문제가 있습니다.
접근 한
내가 고객을 채우기 위해 저장소를 호출 할 때 그러나,보기에서 콤보 상자가 비어의 'OnNavigatedTo'메소드가 생성자 후라고 이해합니다.
뷰 모델 :
public class ViewAViewModel : BindableBase, INavigationAware
{
private readonly IRegionManager _regionManager;
private readonly IRepository _repository;
public List<Customer> Customers { get; set; }
public ViewAViewModel(IRepository repository, IRegionManager regionManager)
{
_repository = repository;
_regionManager = regionManager;
Customers = new List<Customer>();
}
private string _selectedCustomer;
public string SelectedCustomer
{
get { return _selectedCustomer; }
set { SetProperty(ref _selectedCustomer, value); }
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
Customers = _repository.GetCustomers();
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
보기 : 내가 생성자를 통해/채우기 '고객'초기화하면
<UserControl x:Class="ModuleA.Views.ViewA"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid>
<StackPanel>
<ComboBox ItemsSource="{Binding Customers}" DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding SelectedCustomer}"></ComboBox>
</StackPanel>
</Grid>
</UserControl>
, 콤보 모듈은 모듈에 추가 될 때,하지만, 작품이 잘 결합 부트 스트 래퍼의 '고객'저장소 메소드가 불필요하게 호출됩니다. 나는 이상하다고 생각하지 않습니다. 내가 사용하는 경우 콤보가 잘 작동에
접근법 2
은 '고객', 다음 데이터 바인딩에 'RaisePropertyChanged'.
뷰 모델 :
public class ViewAViewModel : BindableBase, INavigationAware
{
private readonly IRegionManager _regionManager;
private readonly IRepository _repository;
private List<Customer> _customers;
public List<Customer> Customers
{
get { return _customers; }
set
{
_customers = value;
RaisePropertyChanged();
}
}
public ViewAViewModel(IRepository repository, IRegionManager regionManager)
{
_repository = repository;
_regionManager = regionManager;
_customers = new List<Customer>();
}
private string _selectedCustomer;
public string SelectedCustomer
{
get { return _selectedCustomer; }
set { SetProperty(ref _selectedCustomer, value); }
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
Customers = _repository.GetCustomers();
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
은 접근이 취할 수있는 올바른 방법인가? 또는 나는 뭔가를 놓친다.
미리 감사드립니다.
두 번째 방법이 정확합니다. 'Customers' 프라퍼티는 바인딩 소스이기 때문에, 그것의 타겟을 업데이트해야한다는 바인딩에 알리기 위해'PropertyChanged' 이벤트를 발생시켜야합니다. 이것은 실제로 일반적인 데이터 바인딩 주제이며 프리즘이나 탐색 기능과 관련이 없습니다. – dymanoid
감사합니다. 분류가 잘못되어 사과드립니다. 그것의 나의 첫번째 질문. –