public void MarkInvalid() { this.IsInvalid = true; VisualStateManager.GoToState(this, "Invalid", true); }
/// <summary> /// Builds the visual tree for the TransitioningContentControl control /// when a new template is applied. /// </summary> public override void OnApplyTemplate() { if (IsTransitioning) { AbortTransition(); } base.OnApplyTemplate(); PreviousContentPresentationSite = GetTemplateChild(PreviousContentPresentationSitePartName) as ContentPresenter; CurrentContentPresentationSite = GetTemplateChild(CurrentContentPresentationSitePartName) as ContentPresenter; if (CurrentContentPresentationSite != null) { CurrentContentPresentationSite.Content = Content; } var _transitionState = default(string); if (!IsRandom) { _transitionState = Transition; } else { int value = random.Next() % 4; switch (value) { case 0: _transitionState = DefaultTransitionState; break; case 1: _transitionState = UpTransitionState; break; case 2: _transitionState = DownTransitionState; break; case 3: _transitionState = ScaleTransitionState; break; } } // hookup currenttransition var transition = GetStoryboard(_transitionState); CurrentTransition = transition; if (transition == null) { string invalidTransition = _transitionState; // revert to default Transition = DefaultTransitionState; throw new ArgumentException( "TransitioningContentControl_TransitionNotFound"); } VisualStateManager.GoToState(this, NormalState, false); VisualStateManager.GoToState(this, _transitionState, true); }
private void RootLayout_PointerPressed(object sender, PointerRoutedEventArgs e) { VisualStateManager.GoToState(this, "Pressed", true); }
private void ButtonContainer_PointerPressed(object sender, PointerRoutedEventArgs e) { VisualStateManager.GoToState(this, "Pressed", true); CustomButtonClicked?.Invoke(); }
private void SetVisualState() { if (AssociatedObject == null || !AssociatedObject.IsLoaded || DataEnum == null) { return; } var stateName = String.IsNullOrEmpty(FinalStateNameFormat) ? DataEnum.ToString() : String.Format(FinalStateNameFormat, DataEnum.ToString()); FrameworkElement stateTarget; var found = VisualStateUtilities.TryFindNearestStatefulControl(AssociatedObject, out stateTarget); if (!found) { stateTarget = AssociatedObject; } bool result = false; if (stateTarget != null) { var stateControl = stateTarget as Control; if (stateControl == null && found) { var groups = VisualStateManager.GetVisualStateGroups(stateTarget); if (groups.Count == 0) { groups = VisualStateManager.GetVisualStateGroups(AssociatedObject); } FindStoryboard(stateName, groups); result = VisualStateUtilities.GoToState(stateTarget, stateName, true); } else { var groups = VisualStateManager.GetVisualStateGroups(stateControl); if (groups.Count == 0) { groups = VisualStateManager.GetVisualStateGroups(AssociatedObject); } FindStoryboard(stateName, groups); result = VisualStateManager.GoToState(stateControl, stateName, true); } } //if (found) //{ // //bool useTransitions = _initialized; // VisualStateUtilities.GoToState(stateTarget, DataEnum.ToString(), true); // //_initialized = true; //} //else //{ // stateTarget = AssociatedObject as Control; // if (stateTarget != null) { // var result = VisualStateManager.GoToState(stateTarget, DataEnum.ToString(), true); // } //} #if DEBUG && DataBoundStateActionDEBUG Debug.WriteLine("DataBoundStateAction {0}, result={1}", DataEnum, result); #endif }
public static void GoToState(this Control control, string stateName, bool useTransitions) { VisualStateManager.GoToState(control, stateName, false); }
public Search() { this.InitializeComponent(); ui_searchResults.ItemsSource = m_searchResultsList; VisualStateManager.GoToState(this, "HideFilters", false); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { VisualStateManager.GoToState(this, "MultiUserMultitouch", true); }
void ThumbnailControl_PointerReleased(object sender, PointerRoutedEventArgs e) { VisualStateManager.GoToState(this, "PointerUp", true); this.ReleasePointerCapture(e.Pointer); }
private void navList_SelectionChanged(object sender, SelectionChangedEventArgs e) { var a = sender as CustomControls.NavList; VisualStateManager.GoToState(sender as CustomControls.NavList, "textSwitcher", true); }
private void SetCurrentOrientation(Control viewStateAwareControl) { VisualStateManager.GoToState(viewStateAwareControl, this.GetViewState(), false); }
private void FooterToNormal() { VisualStateManager.GoToState(LayoutRoot, "Normal", false); VisualStateManager.GoToState(Reply.Content as UserControl, "Normal", false); }
private void FooterToLightMedia(bool isOut) { VisualStateManager.GoToState(LayoutRoot, "LightState" + (isOut ? "Out" : string.Empty), false); VisualStateManager.GoToState(Reply.Content as UserControl, "LightState", false); }
/// <summary> /// Changes the control's visual state(s). /// </summary> /// <param name="name">name of the state</param> /// <param name="useTransitions">True if state transitions should be used.</param> protected void ChangeVisualState(string name, bool useTransitions) { VisualStateManager.GoToState(this, name, useTransitions); }
public void CheckOrientation() { VisualStateManager.GoToState(MyEntry, (this.Width > this.Height) ? "Landscape" : "Portrait"); }
void ThumbnailControl_PointerPressed(object sender, PointerRoutedEventArgs e) { this.CapturePointer(e.Pointer); VisualStateManager.GoToState(this, "PointerDown", true); }
/// <summary> /// /// </summary> /// <param name="control"></param> /// <param name="stateName"></param> public static void GoToState(this Control control, string stateName) { VisualStateManager.GoToState(control, stateName, true); }
/// <summary> /// </summary> /// <param name="sender"> /// </param> /// <param name="e"> /// </param> private void AnimatingContentControlUnloaded(object sender, RoutedEventArgs e) { VisualStateManager.GoToState(this, "AfterUnLoaded", false); }
private void OnImageLoaded(BitmapImage image) { CurrentImage.Source = image; VisualStateManager.GoToState(this, "OnImageChanged", false); }
private void WitButton_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e) { VisualStateManager.GoToState(this, "Normal", false); }
private void callout_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { // Move to a new state! VisualStateManager.GoToState(this, "MouseDownState", true); }
/// <inheritdoc/> protected override void OnPointerPressed(PointerRoutedEventArgs e) { base.OnPointerPressed(e); VisualStateManager.GoToState(this, IsSelected ? PressedSelectedState : PressedState, true); }
private void checkButton_Click(object sender, RoutedEventArgs e) { VisualStateManager.GoToState(this, "Checked", true); }
private void UpdateVisualState() { VisualStateManager.GoToState(this, ViewModel.IsInPomodoro ? "InPomodoro" : "InBreak", _hasLoaded); }
async void OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { try { var x = e.Velocities.Linear.X; // ignore a little bit velocity (+/-0.1) if (x <= -0.1) { CloseSwipeablePane(); } else if (x > -0.1 && x < 0.1) { if (Math.Abs(_panAreaTransform.TranslateX) > Math.Abs(PanAreaInitialTranslateX) / 2) { CloseSwipeablePane(); } else { OpenSwipeablePane(); } } else { OpenSwipeablePane(); } if (this.IsPanSelectorEnabled) { if (sender == _paneRoot) { // if it's a flick, meaning the user wants to cancel the action, so we remove all the highlights; // or it's intended to be a horizontal gesture, we also remove all the highlights if (Math.Abs(e.Velocities.Linear.Y) >= 2 || Math.Abs(e.Cumulative.Translation.X) > Math.Abs(e.Cumulative.Translation.Y)) { foreach (var item in _menuItems) { VisualStateManager.GoToState(item, "Normal", true); } return; } // un-highlight everything first foreach (var item in _menuItems) { VisualStateManager.GoToState(item, "Unselected", true); } // highlight the item that's going to be selected var itemContainer = _menuItems[_toBeSelectedIndex]; VisualStateManager.GoToState(itemContainer, "Selected", true); // do a selection after a short delay to allow visual effect takes place first await Task.Delay(250); _menuHost.SelectedIndex = _toBeSelectedIndex; } else { // recalculate the starting distance _startingDistance = _distancePerItem * _menuHost.SelectedIndex; } } } catch { } }
private void GotoCurrentState(bool animate) { var state = this.IsActive ? StateActive : StateInactive; VisualStateManager.GoToState(this, state, animate); }
private void ChangeVisualState(bool useTransitions) { VisualStateManager.GoToState(this, IsEnabled ? NormalState : DisabledState, useTransitions); }
/// <summary> /// Changes the control's visual state(s). /// </summary> /// <param name="useTransitions">True if state transitions should be used.</param> protected virtual void ChangeVisualState(bool useTransitions) { VisualStateManager.GoToState(this, IsBusy ? VisualStates.StateBusy : VisualStates.StateIdle, useTransitions); VisualStateManager.GoToState(this, IsContentVisible ? VisualStates.StateVisible : VisualStates.StateHidden, useTransitions); }
private void RootLayout_PointerExited(object sender, PointerRoutedEventArgs e) { VisualStateManager.GoToState(this, "Normal", true); Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 1); }
/// <summary> /// 执行下载 /// </summary> /// <param name="p_priorThumbnail">是否优先下载缩略图</param> /// <param name="p_prompt">是否提示下载失败信息</param> /// <returns></returns> internal async Task <bool> Download(bool p_priorThumbnail = false, bool p_prompt = true) { if (State != FileItemState.None || string.IsNullOrEmpty(ID)) { if (p_prompt) { Kit.Warn("当前状态不可下载!"); } return(false); } bool downloadThumb = false; if (p_priorThumbnail) { // 优先下载缩略图时,先判断是否存在 downloadThumb = await AtFile.Exists(ID + ThumbPostfix); // 缩略图不存在时,若为视频文件不下载 if (!downloadThumb && FileType != FileItemType.Image) { return(false); } } string path = Path.Combine(Kit.CachePath, downloadThumb ? GetThumbName() : GetFileName()); FileStream stream = null; try { if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } stream = System.IO.File.Create(path); } catch (Exception ex) { if (p_prompt) { Kit.Warn("创建文件出错!"); } Log.Error(ex, "下载前创建文件出错!"); return(false); } State = FileItemState.Downloading; DownloadInfo info = new DownloadInfo { Path = downloadThumb ? ID + ThumbPostfix : ID, TgtStream = stream, Progress = OnDownloadProgress, }; bool suc = false; _ctsDownload?.Dispose(); _ctsDownload = new CancellationTokenSource(); try { suc = await Downloader.GetFile(info, _ctsDownload.Token); } catch (Exception ex) { Log.Error(ex, "下载出错"); } finally { _ctsDownload?.Dispose(); info.TgtStream.Close(); State = FileItemState.None; } if (!suc) { if (p_prompt) { Kit.Warn(info.Error); } // 未成功,删除缓存文件,避免打开时出错 try { // mono中 FileInfo 的 Exists 状态不同步! if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } catch { } } else { VisualStateManager.GoToState(this, "Cached", true); } return(suc); }