internal static void Evaluate(FrameworkElement elem) { if (elem == null) { return; } var setters = GetSetters(elem); if (setters == null) { return; } if (!elem.IsLoaded) { elem.Loaded += (e, s) => { Evaluate(elem); }; return; } foreach (var setter in setters) { var bindingText = (setter.Binding != null) ? setter.Binding.ToString() : ""; var prefix = (setter.Prefix != null) ? setter.Prefix : ""; var state = prefix + bindingText; var res = ExtendedVisualStateManager.GoToElementState(elem, state, true); } }
private void UpdateLayoutTransition(FrameworkElement child) { if ((child.Visibility != Visibility.Collapsed && child.IsLoaded) || !ShouldSkipInitialLayout) { FrameworkElement visualRoot = GetVisualRoot(child); TagData tagData = new TagData(); tagData.Parent = (VisualTreeHelper.GetParent(child) as FrameworkElement); tagData.ParentRect = ExtendedVisualStateManager.GetLayoutRect(child); tagData.Child = child; tagData.Timestamp = DateTime.Now; try { tagData.AppRect = TranslateRect(tagData.ParentRect, tagData.Parent, visualRoot); } catch (ArgumentException) { if (ShouldSkipInitialLayout) { return; } } EnsureTags(child); object obj = GetIdentityTag(child); if (obj == null) { obj = child; } UpdateLayoutTransitionCore(child, visualRoot, obj, tagData); } }
private void lblMessages_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (this.IsEnabled) { getUserMessages(ConfigurationManager.GetUserAccount(ConfigurationManager.AuthenticatedUser.ID, _accountId).getOption("username")); ExtendedVisualStateManager.GoToElementState(this.LayoutRoot as FrameworkElement, "TwitterMainMessages", true); } }
/// <summary> /// Terminate the user session /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _logout(object sender, System.Windows.RoutedEventArgs e) { if (MessageBox.Show(Properties.Resources.ThisWillTerminateYourSession, Properties.Resources.Logout, MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No) == MessageBoxResult.Yes) { ConfigurationManager.DeAuthenticatedUser(); ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, LoginState.Name, true); userControlPlace.Content = ""; } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); StartTimer(); ExtendedVisualStateManager.GoToState(this, "Entering", true); await Task.Delay(TimeSpan.FromSeconds(3)); ExtendedVisualStateManager.GoToState(this, "Exiting", true); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.NavigationMode == NavigationMode.New) { Task.Delay(TimeSpan.FromSeconds(2)) .ContinueWith(t => { ExtendedVisualStateManager.GoToState(this, "Hiding", true); }, TaskScheduler.FromCurrentSynchronizationContext()); } }
private void TwitterAccountsElementSelected(object sender, System.Windows.RoutedEventArgs e) { TreeViewItem item = e.OriginalSource as TreeViewItem; //If don't have childs is an account or isn't configured //MessageBox.Show(item.DataContext.GetType().Equals(typeof(Account)).ToString()); if (item.DataContext != null && item.DataContext.GetType().Equals(typeof(iBoard.Classes.Data.Twitter.TwitterAccount))) { Account account = item.Header as Account; this._currentAccountToEdit = account.ID; ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, AddTwitterUser1.Name, true); EditOrCreateTwitterAccount(this, null); } }
internal static bool GoToState(FrameworkElement element, string stateName, bool useTransitions) { Control stateTarget = element as Control; if (stateTarget != null) { stateTarget.ApplyTemplate(); return(VisualStateManager.GoToState(stateTarget, stateName, useTransitions)); } else { return(ExtendedVisualStateManager.GoToElementState(element, stateName, useTransitions)); } }
private void MoodleAccountsEditSelected(object sender, System.Windows.RoutedEventArgs e) { TreeViewItem item = e.OriginalSource as TreeViewItem; //If don't have childs is an account if (item.DataContext != null && item.DataContext.GetType().Equals(typeof(MoodleAccount))) { MoodleAccount account = item.Header as MoodleAccount; this._currentAccountToEdit = account.ID; ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, AccountManageMoodleState.Name, true); EditOrCreateMoodleAccount(this, null); } }
private void Command_Completed(object parameter) { if (IsBeingUsedAtRootLevel) { // Invoke the actions InvokeActions(parameter); } else { if (VisualStateManager.GetVisualStateGroups(this.AssociatedObject).Count > 0) { ExtendedVisualStateManager.GoToElementState(this.AssociatedObject, (string)parameter, true); } } }
// authenticate the user private void btnLogin_Click(object sender, System.Windows.RoutedEventArgs e) { if (ConfigurationManager.AuthenticateUser(txtLoginUsername.Text, pbLoginPassword.Password, (Boolean)cbRememberLogin.IsChecked)) { GetUnifiedAccounts(this, null); ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, MainAppState.Name, true); txtWelcome.Content = "Welcome, " + txtLoginUsername.Text; txtLoginUsername.Text = ""; pbLoginPassword.Password = ""; } else { MessageBox.Show("Authentication failed for user " + txtLoginUsername.Text, "Authentication failed", MessageBoxButton.OK, MessageBoxImage.Error); } }
protected override void Invoke(object parameter) { if (!string.IsNullOrWhiteSpace(this.StateName) && _stateTarget != null) { Control _control = _stateTarget as Control; if (_control != null) { _control.ApplyTemplate(); VisualStateManager.GoToState(_control, this.StateName, this.UseTransitions); } else { ExtendedVisualStateManager.GoToElementState(_stateTarget, this.StateName, this.UseTransitions); } } }
private void dataGrid1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { DataGrid dg = e.OriginalSource as DataGrid; MyData data = dg.SelectedItem as MyData; //MessageBox.Show(data.idMessage); StringBuilder mailInfo = new StringBuilder(); mailInfo.AppendLine("From: " + data.fromSender); mailInfo.AppendLine("Subject: " + data.subjectSender); mailInfo.AppendLine("Date: " + data.mailDate); txtMailInfo.Text = mailInfo.ToString(); txtMail.Text = data.textSender; ExtendedVisualStateManager.GoToElementState(this.LayoutRoot as FrameworkElement, MailDetail.Name, true); }
private void showUserTimeline(TwitterResponse <TwitterStatusCollection> userTimeline) { listboxUserTime.Items.Clear(); for (int j = 0; j < userTimeline.ResponseObject.Count; j++) { ListBoxItem itm = new ListBoxItem(); var userTwitt = userTimeline.ResponseObject[j]; //itm.Name = userTwitt.User.ScreenName; itm.Uid = userTwitt.User.Id.ToString(); itm.Content = userTwitt.User.ScreenName + ": " + userTwitt.Text + " (at " + userTwitt.CreatedDate + ")"; listboxUserTime.Items.Add(itm); } imgUser.Source = new BitmapImage(new Uri(@userTimeline.ResponseObject[0].User.ProfileImageLocation)); txtUserInfo.Text = ""; txtUserInfo.Text = showUserDetail(userTimeline.ResponseObject[0].User).ToString(); ExtendedVisualStateManager.GoToElementState(this.LayoutRoot as FrameworkElement, "TwitterUserTimeline", true); }
private void ValidateMailAccount_ButtonClick(object sender, System.Windows.RoutedEventArgs e) { //txtMailAccountName.Text = ""; //txtMailUsername.Text = ""; //smtpserver.Text = ""; //popserver.Text = ""; //portpop.Text = ""; //portsmtp.Text = ""; //txtMailPassword.Password = ""; if (txtMailAccountName.Text == "" || txtMailUsername.Text == "" || smtpserver.Text == "" || popserver.Text == "" || portsmtp.Text == "" || portpop.Text == "" || txtMailPassword.Password.Equals("")) { lblMailUsernameError.Content = "Please fill all fields"; return; } else { Account emailAccount = new Account(); emailAccount.Type = Account.EMAILTYPE; emailAccount.Name = txtMailAccountName.Text; emailAccount.Enabled = cbEnableAccount.IsChecked.Value; emailAccount.addOption("smtpserver", smtpserver.Text); emailAccount.addOption("smtpport", portsmtp.Text); emailAccount.addOption("popserver", popserver.Text); emailAccount.addOption("popport", portpop.Text); emailAccount.addOption("username", txtMailAccountName.Text); emailAccount.addOption("password", ConfigurationManager.AuthenticatedUser.Encrypt(txtMailPassword.Password)); emailAccount.addOption("email", txtMailUsername.Text); emailAccount.addOption("ssl", cbSsl.IsChecked.Value.ToString()); ConfigurationManager.AddUserAccount(emailAccount); ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, "MainAppState", true); } //MessageBox.Show("Aqui tens de fazer a magia acontecer,... linha 440"); // Dá uma vista deolhos de como eu fiz nos dois botões que tenho do twitter //btnAddTwitterUser_Click - este faço as validações, basicas, se os campos estao ou não preenchidos // btnAddTwitterPin_Click aqui movo o ecrã para o inicio //Apenas precisas de fazer tudo num }
private static void calcState(FrameworkElement element, bool useTransitions) { if (element == null) { return; } if (!element.IsLoaded) { element.Loaded += _OnLoaded; return; } var bindingText = GetBinding(element)?.ToString() ?? ""; var prefix = GetPrefix(element) ?? ""; var state = prefix + bindingText; var res = ExtendedVisualStateManager.GoToElementState(element, state, useTransitions); }
private void lblTwitt_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (this.IsEnabled) { if (!listviewFollowers.HasItems) { getUserFriends(ConfigurationManager.GetUserAccount(ConfigurationManager.AuthenticatedUser.ID, _accountId).getOption("username")); } TwitterResponse <TwitterUser> userTimeline = TwitterUser.Show(_authToken, ConfigurationManager.GetUserAccount(ConfigurationManager.AuthenticatedUser.ID, _accountId).getOption("username")); txtUserLastPosts.Text = ""; txtUserLastPosts.Text += new StringBuilder("Last ten twitts: ").AppendLine(); txtUserLastPosts.Text += showUserTimelineLastX(userTimeline.ResponseObject, 10); ExtendedVisualStateManager.GoToElementState(this.LayoutRoot as FrameworkElement, "TwitterMainPost", true); } }
/// <summary> /// Transitions the control between two states. /// </summary> /// <param name="element">The element to transition between states.</param> /// <param name="stateName">The state to transition to.</param> /// <param name="useTransitions">True to use a System.Windows.VisualTransition to transition between states; otherwise, false.</param> /// <returns>True if the control successfully transitioned to the new state; otherwise, false.</returns> /// <exception cref="T:System.ArgumentNullException">Control is null.</exception> /// <exception cref="T:System.ArgumentNullException">StateName is null.</exception> public static bool GoToState(FrameworkElement element, string stateName, bool useTransitions) { bool result = false; if (!string.IsNullOrEmpty(stateName)) { if (element is Control control) { control.ApplyTemplate(); result = VisualStateManager.GoToState(control, stateName, useTransitions); } else { result = ExtendedVisualStateManager.GoToElementState(element, stateName, useTransitions); } } return(result); }
/// <summary> /// On application start /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginWindow_Initialized(object sender, System.EventArgs e) { try { // if we can authenticate the default user, skip to the application directly if (ConfigurationManager.AuthenticateUser()) { GetUnifiedAccounts(this, null); ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, MainAppState.Name, true); txtWelcome.Content = "Welcome, " + ConfigurationManager.AuthenticatedUser.Username; } else { ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, LoginState.Name, true); Keyboard.Focus(txtLoginUsername); } } catch (Exception exception) { MessageBox.Show(String.Format(Properties.Resources.ErrorOccurred, exception.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void UpdateLayoutTransition(FrameworkElement child) { if (child.Visibility == Visibility.Collapsed || !child.IsLoaded) { if (this.ShouldSkipInitialLayout) { return; } } FrameworkElement root = GetVisualRoot(child); TagData newTagData = new TagData(); newTagData.Parent = VisualTreeHelper.GetParent(child) as FrameworkElement; newTagData.ParentRect = ExtendedVisualStateManager.GetLayoutRect(child); newTagData.Child = child; newTagData.Timestamp = DateTime.Now; try { newTagData.AppRect = TranslateRect(newTagData.ParentRect, newTagData.Parent, root); } catch (System.ArgumentException) { if (this.ShouldSkipInitialLayout) { return; } } this.EnsureTags(child); // Now, get the tag for the element. If there is no tag, the element is its own tag. object tag = GetIdentityTag(child); if (tag == null) { tag = child; } this.UpdateLayoutTransitionCore(child, root, tag, newTagData); }
private void calcState(bool useTransitions) { if (AssociatedObject == null) { return; } if (!AssociatedObject.IsLoaded) { AssociatedObject.Loaded += _OnLoaded; return; } var bindingText = Binding?.ToString() ?? ""; var prefix = Prefix ?? ""; var state = prefix + bindingText; var res = ExtendedVisualStateManager.GoToElementState(AssociatedObject, state, useTransitions); }
/// <summary> /// Transitions the control between two states. /// </summary> /// <param name="element">The element to transition between states.</param> /// <param name="stateName">The state to transition to.</param> /// <param name="useTransitions">True to use a System.Windows.VisualTransition to transition between states; otherwise, false.</param> /// <returns>True if the control successfully transitioned to the new state; otherwise, false.</returns> /// <exception cref="System.ArgumentNullException">Control is null.</exception> /// <exception cref="System.ArgumentNullException">StateName is null.</exception> public static bool GoToState(FrameworkElement element, string stateName, bool useTransitions) { bool success = false; if (!string.IsNullOrEmpty(stateName)) { Control targetControl = element as Control; if (targetControl != null) { targetControl.ApplyTemplate(); success = VisualStateManager.GoToState(targetControl, stateName, useTransitions); } else { success = ExtendedVisualStateManager.GoToElementState(element, stateName, useTransitions); } } return(success); }
private void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { HTMLDocument html = (mshtml.HTMLDocument)browser.Document; if (e.Uri.Query.Length == 0) { try { txtTwitterOauthPin.Text = html.getElementById("oauth_pin").innerText.ToString(); txtTwitterOauthPin.Text = txtTwitterOauthPin.Text.Replace(" ", ""); ExtendedVisualStateManager.GoToElementState(this.AccountAddTwitterOverlay as FrameworkElement, AddTwitterUser2.Name, true); this.Cursor = Cursors.Arrow; } catch (Exception) { //MessageBox.Show(e1.Message + "Não foi possivel receber o pin, Verifique os seus dados"); this.Cursor = Cursors.Arrow; lblTwitterPasswordError.Content = "Wrong password"; } } else { try { html.getElementById("username_or_email").setAttribute("value", txtTwitterUsername.Text.ToString()); html.getElementById("session[password]").setAttribute("value", txtTwitterPassword.Password.ToString()); html.getElementById("allow").click(); } catch (Exception e2) { MessageBox.Show(e2.Message + "Não foi possivel preencher o formulário"); MessageBox.Show("É possivel que já exista um user autenticado no twitter. Não foi possivel descobrir como fazer logout"); if (this._parentWindow != null) { this._parentWindow.CancelTwitterAccountEdit(); } } } }
/// <summary> /// Processes group of items (actually selected or deselected), updates row/col spans and put the items into specific states /// </summary> private void ProcessItemsCollection(IList <object> items, GridView gridView, string newStateName, int rowSpan, int colSpan) { VariableSizedWrapGrid vswGrid = null; foreach (object item in items) { GridViewItem gridViewItem = gridView.ItemContainerGenerator.ContainerFromItem(item) as GridViewItem; if (gridViewItem != null) { VariableSizedWrapGrid.SetRowSpan(gridViewItem, rowSpan); VariableSizedWrapGrid.SetColumnSpan(gridViewItem, colSpan); // Update visual state if (newStateName != null && this.TemplateRootElementName != null) { DependencyObject descendant = VisualTreeEnumerator.FindDescendantByName(gridViewItem, this.TemplateRootElementName, false); if (descendant != null) { ExtendedVisualStateManager.GoToElementState(descendant as Grid, newStateName, true); } } if (vswGrid == null) { vswGrid = VisualTreeHelper.GetParent(gridViewItem) as VariableSizedWrapGrid; } } } // Update panel if some of items were updated if (vswGrid != null) { vswGrid.InvalidateMeasure(); } }
private void btnMailBack_Click(object sender, System.Windows.RoutedEventArgs e) { ExtendedVisualStateManager.GoToElementState(this.LayoutRoot as FrameworkElement, Mail.Name, true); }
/// <summary> /// Get back to the main ui state /// </summary> /// <param name="obj"></param> private void GoToMenuState(string obj) { ExtendedVisualStateManager.GoToElementState(LayoutRoot, "Menu", true); }
/// <summary> /// Change Ui state when navigating /// </summary> /// <param name="obj"></param> private void ChangeDisplay(string obj) { ExtendedVisualStateManager.GoToElementState(LayoutRoot, "Navigation", true); }
private void MailButton_Click(object sender, System.Windows.RoutedEventArgs e) { ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, "AccountAddMail", true); }
private void CloseUserManagementOverlayBtn_Click(object sender, System.Windows.RoutedEventArgs e) { ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, LoginState.Name, true); }
private void addAccountBtn_Click(object sender, System.Windows.RoutedEventArgs e) { ExtendedVisualStateManager.GoToElementState(this.BaseGrid as FrameworkElement, NewUserState.Name, true); }