private void ChoiceButton_Click(object sender, RoutedEventArgs e) { string btnName = ((Button)sender).Name; ShoppingChoice choice = ShoppingChoice.TopLeft; if (btnName == "TopRight") { choice = ShoppingChoice.TopRight; } this.ViewModel.Update(ShoppingScreenState.Selected, choice: choice, force: true); }
/// <summary> /// Change the current state of UI, if allowed by timeouts /// </summary> /// <param name="newState">the state to change to</param> /// <param name="choice">customer informatiom</param> /// <param name="force">always change the state and update timer</param> /// <returns>true iff the change was "officially" made (timeouts are reset)</returns> /// Note: we want to prevent too frequent updates here so the customer can react to the prompts public bool Update(ShoppingScreenState newState, ShoppingChoice choice = ShoppingChoice.TopLeft, bool force = false) { if (!force) { // Take care of the cases when there is no real change of state if (newState == CurrentScreenState) { return(false); // keep waiting for change of state } TimeSpan sinceLastUpdate = DateTime.Now - lastStateChangeTime; switch (CurrentScreenState) { // Delay state change to prevent flickering case ShoppingScreenState.Selected: if (sinceLastUpdate.TotalMilliseconds < 5000) { return(false); // let user to absorb the info } break; case ShoppingScreenState.Choice: if (sinceLastUpdate.TotalMilliseconds < 1000) { return(false); // wait for gaze stabilization } break; } } // Now do change the state switch (newState) { case ShoppingScreenState.Choice: break; case ShoppingScreenState.Selected: SetSelectedSubstate(choice); break; } lastStateChangeTime = DateTime.Now; CurrentScreenState = newState; return(true); }
private void SetSelectedSubstate(ShoppingChoice choice) { if (choice == ShoppingChoice.TopLeft) { ImageSourceSelected = imageSourceSelectedTopLeft; SelectedPromoLine1 = ProductCatalog.leftPromoLines[0]; SelectedPromoLine2 = ProductCatalog.leftPromoLines[1]; SelectedPromoLine3 = ProductCatalog.leftPromoLines[2]; } else if (choice == ShoppingChoice.TopRight) { ImageSourceSelected = imageSourceSelectedTopRight; SelectedPromoLine1 = ProductCatalog.rightPromoLines[0]; SelectedPromoLine2 = ProductCatalog.rightPromoLines[1]; SelectedPromoLine3 = ProductCatalog.rightPromoLines[2]; } }