using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; using XAMLFinance.View; using XAMLFinance.ViewModel; namespace XAMLFinance { public partial class InstrumentDetailsPage : PhoneApplicationPage { private static readonly string PivotIndexKey = "PivotIndex"; private InstrumentChartView chartView = null; public InstrumentDetailsPage() { InitializeComponent(); this.OrientationChanged += InstrumentDetailsPage_OrientationChanged; } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); // parse the querystring to extract the id string symbol = NavigationContext.QueryString["symbol"]; // obtain this item from the view model. var viewModel = App.Current.ViewModel.Pricelist.Prices.Single(p => p.Symbol == symbol); viewModel.Init(); this.DataContext = viewModel; if (State.ContainsKey(PivotIndexKey)) { pivot.SelectedIndex = (int)State[PivotIndexKey]; } } protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedFrom(e); // persist the position of the pivot State[PivotIndexKey] = pivot.SelectedIndex; } private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (pivot.SelectedIndex == 2) { // if the 'loading' indicator is present, swap this for the chart if (chartContainer.Children[0] is TextBlock) { Dispatcher.BeginInvoke(() => { chartContainer.Children.Clear(); chartContainer.Children.Add(new InstrumentDetailsChartPivotPage()); }); } } } private void InstrumentDetailsPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { if (e.Orientation == PageOrientation.Portrait || e.Orientation == PageOrientation.PortraitDown || e.Orientation == PageOrientation.PortraitUp) { pivot.Visibility = Visibility.Visible; if (chartView != null) { chartView.Visibility = Visibility.Collapsed; } } else { pivot.Visibility = Visibility.Collapsed; if (chartView == null) { chartView = new InstrumentChartView(); ContentPanel.Children.Add(chartView); } else { chartView.Visibility = Visibility.Visible; } } } private void FavouriteButton_Click(object sender, EventArgs e) { var viewModel = this.DataContext as InstrumentDetailsViewModel; App.Current.ViewModel.Favourites.Add(viewModel.PriceViewModel); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)