I have a graph in a 'detail' view. this is accessed when an item is chosen in a tableview. the first graph is correct, but when I pick another item in the table, it still shows the first graph. I enabled ListenPropertyChange = true
and raispropertychanged
it twice.
view(viewdidload):
SFChart chart = new SFChart();
chart.Frame = this.headerview.Frame;
//Adding Primary Axis for the Chart.
SFCategoryAxis primaryAxis = new SFCategoryAxis();
chart.PrimaryAxis = primaryAxis;
//Adding Secondary Axis for the Chart.
SFNumericalAxis secondaryAxis = new SFNumericalAxis();
chart.SecondaryAxis = secondaryAxis;
SFLineSeries series = new SFLineSeries()
{
XBindingPath = "timestamp",
YBindingPath = "price_btc",
ListenPropertyChange = true
};
series.EnableTooltip = true;
chart.Series.Add(series);
set.Bind(series).For(s => s.ItemsSource).To(vm => vm.CoinHistory);
set.Apply();
viewModel(init):
CoinHistory = new ObservableCollection<ChartDataModel>(_CoinHistoryGraph.Select(x => new ChartDataModel(float.Parse(x.price_btc), x.timestamp)));
RaisePropertyChanged(() => CoinHistory);
ViewModel properties:
private ObservableCollection<ChartDataModel> _CoinHistory;
public ObservableCollection<ChartDataModel> CoinHistory
{
get
{
return _CoinHistory;
}
set
{
_CoinHistory = value;
RaisePropertyChanged(() => CoinHistory);
}
}
How do you pass your model data to the details view? According to your descriptions, the first ViewModel should hold the whole data. When user click one cell, the tableView source's SelectionChangedCommand
event will trigger. Normally we bind this command to the corresponding ViewModel's command, then we can configure the push and pass the parameters there.
Here is my bind in the first view which contains a UITableView
:
var set = this.CreateBindingSet<FirstView, FirstViewModel>();
set.Bind(source).For(s => s.ItemsSource).To(vm => vm.ItemsGroup);
set.Bind(source).For(s => s.SelectionChangedCommand).To(vm => vm.ShowDetailsCommand);
set.Apply();
When user click one cell in the TableView, ShowDetailsCommand
will fire in the FirstViewModel
:
private readonly Lazy<IMvxNavigationService> _navigationService = new Lazy<IMvxNavigationService>(Mvx.Resolve<IMvxNavigationService>);
private MvxCommand<Item> showDetailsCommand;
public ICommand ShowDetailsCommand
{
get
{
return showDetailsCommand ?? (showDetailsCommand = new MvxCommand<Item>(showDetails));
}
}
async void showDetails(Item item)
{
// This item is bound to the ItemsSource through ItemsGroup
await _navigationService.Value.Navigate<SecondViewModel, Item>(item);
}
Then the second ViewModel can accept this item via:
public class SecondViewModel : MvxViewModel<Item>
{
private List<CoinHistoryModel> _CoinHistory;
public List<CoinHistoryModel> CoinHistory
{
get
{
return _CoinHistory;
}
set
{
_CoinHistory = value;
RaisePropertyChanged(() => CoinHistory);
}
}
public override void Prepare(Item parameter)
{
CoinHistory = parameter.SingleCoinHistory;
}
}
At last the details view will show the CoinHistory
, if you have successfully bound it to the second view model.
Here is my demo for you referring to.