public OptionsViewModel(OptionsPageData data, ObservableValue<IEnumerable<string>> exceptionNames) { _data = data; IgnoredPatterns = new PatternCollectionViewModel(data.Ignored); AllExceptions = exceptionNames.GetObservable(v => new ReadOnlyCollection<ExceptionViewModel>( v.Select(n => new ExceptionViewModel(n, IgnoredPatterns.Selected)).ToArray() )); _exceptionsMatchingIgnored = new ObservableCollection<ExceptionViewModel>(); ExceptionsMatchingIgnored = new ReadOnlyObservableCollection<ExceptionViewModel>(_exceptionsMatchingIgnored); AllExceptions.ValueChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); IgnoredPatterns.Values.CollectionChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); var ignoredChangeHandler = (EventHandler) delegate { RecalculateExceptionsMatchingIgnored(); }; IgnoredPatterns.Values.AddHandlers( added => { added.Pattern.ValueChanged += ignoredChangeHandler; added.Enabled.ValueChanged += ignoredChangeHandler; }, removed => { removed.Pattern.ValueChanged -= ignoredChangeHandler; removed.Enabled.ValueChanged -= ignoredChangeHandler; } ); RecalculateExceptionsMatchingIgnored(); }
public ExceptionViewModel(string name, ObservableValue<PatternViewModel> selected) { Name = name; MatchesSelected = selected.GetObservable( s => s != null && !s.IsEmpty.Value && s.Data.Matches(name), (newItem, oldItem, changed) => { var handler = (EventHandler)delegate { changed(); }; if (oldItem != null) { oldItem.Pattern.ValueChanged -= handler; oldItem.Enabled.ValueChanged -= handler; } if (newItem != null) { newItem.Pattern.ValueChanged += handler; newItem.Enabled.ValueChanged += handler; } } ); }
public SystemClockBehavior( GameStateModel gameState) { _gameState = gameState; _utcNow = new ObservableValue <DateTimeOffset>(DateTimeOffset.Now); }
public Dashboard() { InitializeComponent(); goodValue = new ObservableValue(10); badValue = new ObservableValue(10); neutralValue = new ObservableValue(100); goodOne.Values = new ChartValues <ObservableValue> { goodValue }; badOne.Values = new ChartValues <ObservableValue> { badValue }; neutralOne.Values = new ChartValues <ObservableValue> { neutralValue }; PointLabel = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation); DataContext = this; connector = new Connector(); updateClassList(); Thread thread = new Thread(new ThreadStart(sync)); thread.Start(); }
public void TestActionModificationPickup1() { var a = ObservableValue <int> .From(1); var i = 3; var b = 0; Reactions.Autorun(r => { b = a.Value * 2; }); Assert.Equal(2, b); var action = Actions.CreateAction("action", () => { a.Value = ++i; }); action(); Assert.Equal(8, b); action(); Assert.Equal(10, b); }
public TestExpression(object value, bool isReadOnly = false) { observableValue = new ObservableValue(value); observableValue.ValueChanged += (sender, e) => ValueChanged.Raise(this, e); this.isReadOnly = isReadOnly; }
public MainWindow() { InitializeComponent(); this.DataContext = this; IsReading = true; VoltageValues = new ObservableValue(0); CurrentValues = new ObservableValue(1); WattValues = new ObservableValue(2); EnergyValues = new ObservableValue(3); var mapper = Mappers.Xy <MeasureModel>() .X(model => model.DateTime.Ticks / TimeSpan.FromTicks(1).Ticks) //use DateTime.Ticks as X (Cannot be FromSeconds() else the graph won't show anything!) .Y(model => model.Value); //use the value property as Y //lets set how to display the X Labels (mm:ss) DateTimeFormatter = value => new DateTime((long)value).ToString("mm:ss"); //lets save the mapper globally. Charting.For <MeasureModel>(mapper); //the values property will store our values array VoltageChartValues = new ChartValues <MeasureModel>(); // For the voltage cartesian graph values CurrentChartValues = new ChartValues <MeasureModel>(); // For the current cartesian graph values WattChartValues = new ChartValues <MeasureModel>(); EnergyChartValues = new ChartValues <MeasureModel>(); //AxisStep forces the distance between each separator in the X axis AxisStep = TimeSpan.FromSeconds(1).Ticks; //AxisUnit forces lets the axis know that we are plotting seconds //this is not always necessary, but it can prevent wrong labeling AxisUnit = TimeSpan.TicksPerSecond; SetAxisLimits(DateTime.Now); }
private void RemoveState(ObservableValue <string> state) { var index = _states.IndexOf(_states.FirstOrDefault(s => s.Key.Equals(state))); _states.RemoveAt(index); _stateRemoveCallback(); }
public OptionsViewModel(OptionsPageData data, ObservableValue <IEnumerable <string> > exceptionNames) { _data = data; IgnoredPatterns = new PatternCollectionViewModel(data.Ignored); AllExceptions = exceptionNames.GetObservable(v => new ReadOnlyCollection <ExceptionViewModel>( v.Select(n => new ExceptionViewModel(n, IgnoredPatterns.Selected)).ToArray() )); _exceptionsMatchingIgnored = new ObservableCollection <ExceptionViewModel>(); ExceptionsMatchingIgnored = new ReadOnlyObservableCollection <ExceptionViewModel>(_exceptionsMatchingIgnored); AllExceptions.ValueChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); IgnoredPatterns.Values.CollectionChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); var ignoredChangeHandler = (EventHandler) delegate { RecalculateExceptionsMatchingIgnored(); }; IgnoredPatterns.Values.AddHandlers( added => { added.Pattern.ValueChanged += ignoredChangeHandler; added.Enabled.ValueChanged += ignoredChangeHandler; }, removed => { removed.Pattern.ValueChanged -= ignoredChangeHandler; removed.Enabled.ValueChanged -= ignoredChangeHandler; } ); RecalculateExceptionsMatchingIgnored(); }
public OptionsPageData(Lazy <IExceptionListProvider> exceptionListProvider, Lazy <IDiagnosticLogger> logger) { _exceptionListProvider = exceptionListProvider; _logger = logger; Ignored = new List <PatternData>(); ShowDiagnosticsObservable = new ObservableValue <bool>(); }
public void TestWrapInTransaction() { var values = new List <int>(); var observable = ObservableValue <int> .From(0); Reactions.Autorun(r => { values.Add(observable.Value); }); var increment = Actions.CreateAction <int, int>("Increment", (amount) => { observable.Value += amount * 2; observable.Value -= amount; // oops return(observable.Value); }); var value = increment(7); Assert.Equal(7, value); Assert.Equal(2, values.Count); Assert.Equal(0, values[0]); Assert.Equal(7, values[1]); }
public void TestActionModificationPickup3() { var a = ObservableValue <int> .From(1); var b = 0; var doubler = ComputedValue <int> .From(() => a.Value * 2); doubler.Observe(change => { b = doubler.Value; }, true); Assert.Equal(2, b); var action = Actions.CreateAction("action", () => { a.Value = a.Value + 1; // ha, no loop! }); action(); Assert.Equal(4, b); action(); Assert.Equal(6, b); }
public void TestDynamic() { var x = ObservableValue <int> .From(3); var xreader = x as IValueReader <int>; var xwriter = x as IValueWriter <int>; var y = ComputedValue <int> .From(() => xreader.Value); var values = new List <int>(); var diposable = y.Observe(change => { values.Add(change.NewValue); }, true); Assert.Equal(3, y.Value); xwriter.Value = 5; Assert.Equal(5, y.Value); Assert.Equal(2, values.Count); Assert.Equal(3, values[0]); Assert.Equal(5, values[1]); }
public void TestObservableAutoRun() { var box = ObservableValue <int> .From(1); var reader = box as IValueReader <int>; var writer = box as IValueWriter <int>; var values = new List <int>(); Reactions.Autorun((reaction) => { Assert.NotNull(reaction); if (reader.Value == -1) { reaction.Dispose(); } values.Add(reader.Value); }); writer.Value = 2; writer.Value = 2; writer.Value = -1; writer.Value = 3; writer.Value = 4; Assert.Equal(3, values.Count); Assert.Equal(1, values[0]); Assert.Equal(2, values[1]); Assert.Equal(-1, values[2]); }
public void TestDynamic2() { var x = ObservableValue <int> .From(3); var xreader = x as IValueReader <int>; var xwriter = x as IValueWriter <int>; var y = ComputedValue <int> .From(() => xreader.Value *xreader.Value); Assert.Equal(9, y.Value); var values = new List <int>(); var diposable = y.Observe(change => { values.Add(change.NewValue); }); xwriter.Value = 5; Assert.Equal(25, y.Value); Assert.Single(values); Assert.Equal(25, values[0]); }
public ValueOverlapExpression() { values = new List <Tuple <object, object> >(); observableValue = new ObservableValue(); observableValue.ValueChanged += (sender, oldValue, newValue) => ValueChanged.Raise(this, oldValue, newValue); }
public LogInfoWindow() { InitializeComponent(); Band6 = new ObservableValue(); Band10 = new ObservableValue(); Band12 = new ObservableValue(); Band15 = new ObservableValue(); Band17 = new ObservableValue(); Band20 = new ObservableValue(); Band30 = new ObservableValue(); Band40 = new ObservableValue(); Band60 = new ObservableValue(); Band80 = new ObservableValue(); Band160 = new ObservableValue(); CW = new ObservableValue(); SSB = new ObservableValue(); PSK = new ObservableValue(); RTTY = new ObservableValue(); FT8 = new ObservableValue(); PointLabel = chartPoint => string.Format("{0} ({1:P})", chartPoint.SeriesView.Title, chartPoint.Participation); BindCharts(); DataContext = this; }
public void TestActionModificationPickup2() { var a = ObservableValue <int> .From(1); var b = 0; Reactions.Autorun(r => { b = a.Value * 2; }); Assert.Equal(2, b); var action = Actions.CreateAction("action", () => { a.Value = a.Value + 1; // ha, no loop! }); action(); Assert.Equal(4, b); action(); Assert.Equal(6, b); }
async void getInforSARS(string uri) { try { var html = await HtmlWeb.LoadFromWebAsync(uri); var getCounter = html.DocumentNode.SelectNodes("//div[contains(@class, 'UvMayb')]"); //--------------------------------------------------------------------------------------// totalConf.Content = getCounter[0].InnerText; totalRec.Content = getCounter[1].InnerText; totalMortos.Content = getCounter[2].InnerText; //---------------------------------------------// double c = 0; double r = 0; double m = 0; //---------------------------------------------------------// double.TryParse((string)totalConf.Content, out c); double.TryParse((string)totalRec.Content, out r); double.TryParse((string)totalMortos.Content, out m); //---------------------------------------------// c2020[0] = new ObservableValue(c); c2020[1] = new ObservableValue(r); c2020[2] = new ObservableValue(m); //---------------------------------------------// c2019[0] = new ObservableValue(c * 0.2); c2019[1] = new ObservableValue(r * 0.2); c2019[2] = new ObservableValue(m * 0.2); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void TestRunInAction() { var observable = ObservableValue <int> .From(0); var values = new List <int>(); var d = Reactions.Autorun(() => values.Add(observable.Value)); var res = Actions.RunInAction <int>("increment", () => { observable.Value = observable.Value + 6 * 2; observable.Value = observable.Value - 3; // oops return(2); }); Assert.Equal(2, res); Assert.Equal(new[] { 0, 9 }, values.ToArray()); res = Actions.RunInAction <int>("another", () => { observable.Value = observable.Value + 5 * 2; observable.Value = observable.Value - 4; // oops return(3); }); Assert.Equal(3, res); Assert.Equal(new[] { 0, 9, 15 }, values.ToArray()); d.Dispose(); }
public void TestActionAutorunUnTracked() { var a = ObservableValue <int> .From(2); var b = ObservableValue <int> .From(3); var values = new List <int>(); var multiplier = Actions.CreateAction <int, int>("multiplier", (val) => val * b.Value); var d = Reactions.Autorun(() => { values.Add(multiplier(a.Value)); }); a.Value = 3; b.Value = 4; a.Value = 5; d.Dispose(); a.Value = 6; Assert.Equal(new[] { 6, 9, 20 }, values.ToArray()); }
public void TestAutorunInAction() { var a = ObservableValue <int> .From(1); var values = new List <int>(); var adder = Actions.CreateAction <int, IDisposable>("incr", (incr) => { return(Reactions.Autorun(() => { values.Add(a.Value + incr); })); }); var d1 = adder(2); a.Value = 3; var d2 = adder(17); a.Value = 24; d1.Dispose(); a.Value = 11; d2.Dispose(); a.Value = 100; // n.b. order could swap as autorun creation order doesn't guarantee stuff Assert.Equal(new int[] { 3, 5, 20, 26, 41, 28 }, values.ToArray()); }
public void ObservableValueBaseChangedTest() { int valueChangedCount = 0; ObservableValue observableValue = new ObservableValue(); observableValue.ValueChanged += (sender, oldValue, newValue) => valueChangedCount++; Assert.AreEqual(ObservableValue.UnsetValue, observableValue.Value); Assert.IsTrue(ObservableValue.IsNullOrUnset(observableValue.Value)); ObservableValue baseObservableValue = new ObservableValue(); observableValue.BaseValue = baseObservableValue; Assert.AreEqual(0, valueChangedCount); baseObservableValue.BaseValue = "value1"; Assert.AreEqual(1, valueChangedCount); baseObservableValue.BaseValue = "value1"; Assert.AreEqual(1, valueChangedCount); baseObservableValue.BaseValue = "value1a"; Assert.AreEqual(2, valueChangedCount); observableValue.BaseValue = "value2"; Assert.AreEqual(3, valueChangedCount); baseObservableValue.BaseValue = "value1b"; Assert.AreEqual(3, valueChangedCount); }
void Start() { intAsObservable = new ObservableValue <int>(intValue); intAsObservable.OnValueChange = (i) => { Debug.Log("change value:" + i.ToString()); }; }
public void TestIntValue() { var box = ObservableValue <int> .From(5); var reader = box as IValueReader; Assert.Equal(5, reader.Value); }
public Order() { Vat = ObservableValue <double> .From(0.2); Price = ObservableValue <double> .From(10); PriceWithVat = ComputedValue <double> .From(() => (Price as IValueReader <double>).Value *(1 + (Vat as IValueReader <double>).Value)); }
public ActionCommand(Action execute, IObservableReadOnlyValue <bool> canExecute) { _execute = execute ?? throw new ArgumentNullException(nameof(execute)); CanExecute = canExecute ?? ObservableValue.Create(true); _canExecuteSubscription = canExecute?.Subscribe(x => CanExecuteChanged?.Invoke(this, EventArgs.Empty)); }
public void TestNullValue() { var box = ObservableValue <object> .From(null); var reader = box as IValueReader; Assert.Null(reader.Value); }
public GameBoardTileModel(ushort colIndex, ushort rowIndex) { ColIndex = colIndex; Content = new ObservableValue <DominoModel>(); IsFaceUp = new ObservableValue <bool>(); IsRotated = new ObservableValue <bool>(); RowIndex = rowIndex; }
public AsyncActionCommand(Func <CancellationToken, Task> executeAsync, IObservableReadOnlyValue <bool> canExecute) { _executeAsync = executeAsync ?? throw new ArgumentNullException(nameof(executeAsync)); CanExecute = canExecute ?? ObservableValue.Create(true); _canExecuteSubscription = canExecute?.Subscribe(x => CanExecuteChanged?.Invoke(this, EventArgs.Empty)); }
public MutationDocumentsExecutionResultModel() { MutationScore = "0%"; CompletedMutationDocuments = new ObservableCollection <MutationDocumentResult>(); SurvivedMutationDocuments = new ObservableCollection <MutationDocumentResult>(); MutationsSurvivedCount = new ObservableValue(); MutationsKilledCount = new ObservableValue(); }
/// <summary> /// Creates an <see cref="IObservableCommand{T}"/> available via data binding. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="viewModel"></param> /// <param name="name"></param> /// <returns></returns> public static IObservableCommand <T> CreateObservableCommand <T>(this BaseViewModel viewModel, string name) { var observableValue = new ObservableValue <IObservableCommand <T> >(new ObservableCommand <T>()); viewModel.AddProperty <IObservableCommand <T> >(name, observableValue); return(observableValue.Latest); }
public void SetupFilters() { source = new TestObservableCollection<int>() { 1, 2, 3, 4, }; value = source.AsObservableQuery() .Observe(i => i.Max()); }
/// <summary> /// Initializes the <see cref="ConfigurationContext" /> class. /// </summary> public ConfigurationContext(IStorage storageProvider) { _storageProvider = storageProvider; ToolbarState = new ObservableValue<ExpansionStates>(); IsBusy = new ObservableValue<bool>(false, true); IsTrackingCurrentLocation = new ObservableValue<bool>(); IsOnline = new ObservableValue<bool>(true); IsBusy.ValueChanging += OnIsLoadingChanging; }
public SchedulePage() { this.InitializeComponent(); MainPage.Title.Value = "Schedule"; _scheduleCaller = new SpartaHackSchedule(); Schedule = new ObservableValue<List<Schedule>>(); DataContext = this; init(); }
public MainPage(Frame frame) { this.InitializeComponent(); Title = new ObservableValue<string>(); LoggedIn = new ObservableValue<bool>(); this.MySplitView.Content = frame; DataContext = Title; }
public void SimpleValueTest() { var o = new TestObject(); var w = new ObservableValue<bool>(() => o.TheValue.StartsWith("A")); o.TheValue = "Bob"; Assert.IsFalse(w.Value); o.TheValue = "Aaron"; Assert.IsTrue(w.Value); }
private void init() { LoggedIn = new ObservableValue<bool>(); LoggedIn.Value = false; MainPage.LoggedIn = LoggedIn; MainPage.Title.Value = "Login"; userRepo = new SpartaHackUser(); User = SpartaHackUser.getCurrentUser(); DataContext = this; }
private UIElement CreateChild() { var manager = _exceptionListProvider.Value; var exceptionNamesObservable = new ObservableValue<IEnumerable<string>>(manager.GetExceptionNames()); _exceptionListProvider.Value.ExceptionNamesChanged += delegate { var count = 0; exceptionNamesObservable.Value = manager.GetExceptionNames() .OnAfterEach(_ => count += 1) .OnAfterLast(_ => _logger.Value.WriteLine("Options: Found {0} exceptions for preview.", count)); }; return new OptionsPageView { Model = new OptionsViewModel(this, exceptionNamesObservable) }; }
public PatternCollectionViewModel(ICollection<PatternData> data) { Argument.NotNull("data", data); _data = data; Values = new ObservableCollection<PatternViewModel>(data.Select(d => new PatternViewModel(d))); SetupValues(); Selected = new ObservableValue<PatternViewModel>(); CanAdd = Values.GetObservable(c => c.All(v => !v.IsEmpty.Value), (c, e, changed) => { var handler = (EventHandler)delegate { changed(); }; e.ProcessChanges<PatternViewModel>( newItem => newItem.IsEmpty.ValueChanged += handler, oldItem => oldItem.IsEmpty.ValueChanged -= handler ); }); CanDelete = Selected.GetObservable(v => v != null); }
//! stores the historical fixings of the index public void setHistory(string name, ObservableValue<TimeSeries<double>> history) { checkExists(name); data_[name].Assign(history); }
public void testSwaps() { //BOOST_MESSAGE("Testing Hull-White swap pricing against known values..."); Date today; //=Settings::instance().evaluationDate();; Calendar calendar = new TARGET(); today = calendar.adjust(Date.Today); Settings.setEvaluationDate(today); Date settlement = calendar.advance(today, 2, TimeUnit.Days); Date[] dates = { settlement, calendar.advance(settlement,1,TimeUnit.Weeks), calendar.advance(settlement,1,TimeUnit.Months), calendar.advance(settlement,3,TimeUnit.Months), calendar.advance(settlement,6,TimeUnit.Months), calendar.advance(settlement,9,TimeUnit.Months), calendar.advance(settlement,1,TimeUnit.Years), calendar.advance(settlement,2,TimeUnit.Years), calendar.advance(settlement,3,TimeUnit.Years), calendar.advance(settlement,5,TimeUnit.Years), calendar.advance(settlement,10,TimeUnit.Years), calendar.advance(settlement,15,TimeUnit.Years) }; double[] discounts = { 1.0, 0.999258, 0.996704, 0.990809, 0.981798, 0.972570, 0.963430, 0.929532, 0.889267, 0.803693, 0.596903, 0.433022 }; //for (int i = 0; i < dates.Length; i++) // dates[i] + dates.Length; LogLinear Interpolator = new LogLinear(); Handle<YieldTermStructure> termStructure = new Handle<YieldTermStructure>( new InterpolatedDiscountCurve<LogLinear>( dates.ToList<Date>(), discounts.ToList<double>(), new Actual365Fixed(),new Calendar(), null, null , Interpolator) ); HullWhite model = new HullWhite(termStructure); int[] start = { -3, 0, 3 }; int[] length = { 2, 5, 10 }; double[] rates = { 0.02, 0.04, 0.06 }; IborIndex euribor = new Euribor6M(termStructure); IPricingEngine engine = new TreeVanillaSwapEngine(model, 120, termStructure); #if QL_USE_INDEXED_COUPON double tolerance = 4.0e-3; #else double tolerance = 1.0e-8; #endif for (int i=0; i<start.Length; i++) { Date startDate = calendar.advance(settlement,start[i],TimeUnit.Months); if (startDate < today) { Date fixingDate = calendar.advance(startDate,-2,TimeUnit.Days); //TimeSeries<double> pastFixings; ObservableValue<TimeSeries<double>> pastFixings = new ObservableValue<TimeSeries<double>>(); pastFixings.value()[fixingDate] = 0.03; IndexManager.instance().setHistory(euribor.name(), pastFixings); } for (int j=0; j<length.Length; j++) { Date maturity = calendar.advance(startDate, length[i], TimeUnit.Years); Schedule fixedSchedule = new Schedule(startDate, maturity, new Period(Frequency.Annual), calendar, BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Forward, false); Schedule floatSchedule = new Schedule(startDate, maturity, new Period(Frequency.Semiannual), calendar, BusinessDayConvention.Following, BusinessDayConvention.Following, DateGeneration.Rule.Forward, false); for (int k=0; k<rates.Length; k++) { VanillaSwap swap = new VanillaSwap(VanillaSwap.Type.Payer, 1000000.0, fixedSchedule, rates[k], new Thirty360(), floatSchedule, euribor, 0.0, new Actual360()); swap.setPricingEngine(new DiscountingSwapEngine(termStructure)); double expected = swap.NPV(); swap.setPricingEngine(engine); double calculated = swap.NPV(); double error = Math.Abs((expected-calculated)/expected); if (error > tolerance) { Assert.Fail("Failed to reproduce swap NPV:" //+ QL_FIXED << std::setprecision(9) + "\n calculated: " + calculated + "\n expected: " + expected //+ QL_SCIENTIFIC + "\n rel. error: " + error); } } } } }
public void ListenCharacterSelectedChanged(ObservableValue<CharacterType> _value) { type = _value; }
/// <summary> /// Initializes a new instance of the <see cref="MapViewModel" /> class. /// </summary> public MapViewModel() { _data = ApplicationContext.Data; _configuration = ApplicationContext.Configuration; _navigation = ApplicationContext.NavigationService; if (IsCompassSupported) { _compass = new Compass {TimeBetweenUpdates = TimeSpan.FromMilliseconds(200)}; _compass.CurrentValueChanged += OnCompassReadingChanged; } // Initialise local properties. VisualState = new ObservableValue<VisualStates>(); Suggestions = new ReadOnlyObservableCollection<SearchSuggestion>(_suggestions); Pushpins = new AdaptedObservableCollection<Place, PlaceViewModel>(p => new PlaceViewModel(p, this), source: _data.Places); Routes = new AdaptedObservableCollection<Route, RouteViewModel>(r => new RouteViewModel(r, this), source: _data.Routes); DepartureLocation = new RouteLocation(); ArrivalLocation = new RouteLocation(); // Initialise commands. CommandGetSuggestions = new DelegateCommand(OnGetSuggestions); CommandSearch = new DelegateCommand(OnSearch); CommandAddPlace = new DelegateCommand<Location>(OnAddPlace); CommandSelectPushpin = new DelegateCommand<PlaceViewModel>(vm => SelectedPushpin = vm); CommandSelectRoute = new DelegateCommand<RouteViewModel>(vm => SelectedRoute = vm); CommandDeletePlace = new DelegateCommand<PlaceViewModel>(OnDeletePlace); CommandUpdatePlace = new DelegateCommand<PlaceViewModel>(OnUpdatePlace); CommandStopTrackingCurrentLocation = new DelegateCommand(OnStopTrackingCurrentLocation); CommandGoToDefaultState = new DelegateCommand(OnGoToDefaultState); CommandAddCurrentPlace = new DelegateCommand(() => OnAddPlace(CurrentLocation.ToLocalLocation()), () => CurrentLocation != null && !CurrentLocation.IsUnknown); CommandZoomIn = new DelegateCommand(() => { if (ZoomLevel.Value < MaxZoomLevel) ZoomLevel.Value = Math.Min(ZoomLevel.Value += ZoomStep, MaxZoomLevel); }); CommandZoomOut = new DelegateCommand(() => { if (ZoomLevel.Value > MinZoomLevel) ZoomLevel.Value = Math.Max(ZoomLevel.Value -= ZoomStep, MinZoomLevel); }); CommandShowStreetLayer = new DelegateCommand(() => _data.MapBaseLayer.Value = Layer.Street); CommandShowSatelliteHybridLayer = new DelegateCommand(() => _data.MapBaseLayer.Value = Layer.SatelliteHybrid); CommandToggleMapOverlay = new DelegateCommand<Layer>(_data.ToggleMapOverlay); CommandToggleToolbar = new DelegateCommand(_configuration.ToggleToolbarState); CommandSetDepartLocationToCurrentLocation = new DelegateCommand(() => DepartureLocation.Address = CurrentLocationString); CommandSetArriveLocationToCurrentLocation = new DelegateCommand(() => ArrivalLocation.Address = CurrentLocationString); CommandRoute = new DelegateCommand(OnRoute); CommandActivate = new DelegateCommand(OnActivate); CommandDeactivate = new DelegateCommand(OnDeactivate); CommandSwapRouteLocations = new DelegateCommand(OnSwapRouteLocations); CommandSelectContactAddress = new DelegateCommand(OnSelectContactAddress); CommandSelectDepartLocationFromContacts = new DelegateCommand(OnSelectDepartLocationFromContacts); CommandSelectArriveLocationFromContacts = new DelegateCommand(OnSelectArriveLocationFromContacts); // Initialise application bar button and menu items sources. InitializeAppBarButtonSources(); InitializeAppBarMenuItemsSource(); // Handle events. Pushpins.CollectionChanged += OnPushpinsCollectionChanged; _data.MapBaseLayer.ValueChanged += (old, @new) => RaisePropertyChanged(IsStreetLayerVisibleProperty, IsSatelliteHybridLayerVisibleProperty); _data.SelectedPlace.ValueChanged += (old, @new) => SelectedPushpin = Pushpins.FirstOrDefault(p => p.Data == @new); _data.MapOverlays.CollectionChanged += (s, e) => RaisePropertyChanged(IsTrafficLayerVisibleProperty, IsTransitLayerVisibleProperty); _data.ClearRoutesBeforeAddingNewRoute.ValueChanged += (old, @new) => RaisePropertyChanged(GetRouteButtonTextProperty); VisualState.ValueChanged += OnVisualStateChanged; IsTrackingCurrentLocation.ValueChanged += OnIsTrackingCurrentLocationValueChanged; // Automatically track current position at first run. if (_data.LastRanVersion == null) IsTrackingCurrentLocation.Value = true; #if DEBUG if (DesignerProperties.IsInDesignTool) return; #endif // Initialise geo-coordinate watcher. _geoWatcher = ApplicationContext.GeoCoordinateWatcher; _geoWatcher.PositionChanged += OnGeoWatcherPositionChanged; // Try centering on current location if available. if (IsTrackingCurrentLocation.Value) { if (!_geoWatcher.Position.Location.IsUnknown) { Center.Value = _geoWatcher.Position.Location; ZoomLevel.Value = 15; } } }
void ListenScoreChanged(ObservableValue<int> _statistic) { score = _statistic; }