1
我正在用Windows Phone 8.1應用程序開發MVVMLight。我們有一個按姓氏或名字對用戶列表進行排序的設置。在更改此設置(由設置爲SettingsViewModel中的屬性的ListPicker執行)後,我想調用另一視圖模型(OtherViewModel)中的方法來重新排列OtherViewModel相應視圖上的用戶列表。正在使用settingsStore將分類設置存儲在用戶的手機上。從一個視圖模型調用不同視圖模型的方法
我不希望通過var vm = new ViewModel()
創建視圖模型依賴關係,因爲兩個視圖模型之間沒有父/子關係。我被告知委託人是一個不錯的選擇,但我不太瞭解如何使用委託實施解決方案。
任何幫助,將不勝感激。
設置查看
<toolkit:ListPicker x:Name="ContactsSortParametersListPicker"
ItemsSource="{Binding ContactsSortParameters, Mode=OneTime}"
SelectedItem="{Binding ContactsSortParametersSelected, Mode=TwoWay}"
SelectionChanged="ContactsSortParametersListPicker_SelectionChanged"/>
設置查看(代碼隱藏)
private void ContactsSortParametersListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// want to call method from MainViewModel that updates a list in Main View
}
SettingsViewModel
public IEnumerable<SortOptions> ContactsSortParameters
{
get { return (IEnumerable<SortOptions>)Enum.GetValues(typeof(SortOptions)); }
}
private SortOptions _sortContactsParameterSelected;
public SortOptions ContactsSortParametersSelected
{
get { return _sortContactsParameterSelected; }
set
{
SetProperty(ref _sortContactsParameterSelected, value);
_settingsStore.ContactsSortParameter = _sortContactsParameterSelected;
}
}
OtherViewModel
public async Task LoadDirectory()
{
...relevant logic here...
}
正是我一直在尋找的是新MVVM。謝謝你的幫助! – killQuotes 2014-10-31 21:18:11