/// <summary> /// 设置按钮的文字 /// </summary> /// <param name="text">按钮显示的文字</param> /// <param name="waiting">是否等待,设置为null时显示位原始状态</param> public void UpdateButton(string text, bool?waiting = null) { if (waiting.HasValue) { IsWaiting(waiting.Value); } else { IsWaiting(ButtonHelper.GetIsWaiting(LaunchButton)); } void IsWaiting(bool w) { if (w) { Dispatcher.Invoke(() => { ButtonHelper.SetWaitingContent(LaunchButton, text); ButtonHelper.SetIsWaiting(LaunchButton, true); TabItemChangeButton.IsEnabled = false; }); } else { Dispatcher.Invoke(() => { LaunchButton.Content = text; ButtonHelper.SetIsWaiting(LaunchButton, false); TabItemChangeButton.IsEnabled = true; }); } isWaiting = waiting.Value; } }
private void LoginEventBtnClick(object sender, System.Windows.RoutedEventArgs e) { if (ButtonHelper.GetIsWaiting(this.LoginBtn)) { this.cancellationOperation = true; bw.CancelAsync();//取消后台操作 ButtonHelper.SetIsWaiting(this.LoginBtn, false); } else { ButtonHelper.SetIsWaiting(this.LoginBtn, true); } this.LoginBtn.IsEnabled = true; try { bw.RunWorkerAsync(); } catch (Exception) { //报错无视 } }
private void UpdateCode() { var buttonStyle = ButtonHelper.GetButtonStyle(BtnCustom); var cornerRadius = SldCornerRadius.Value; var isWaiting = ButtonHelper.GetIsWaiting(BtnCustom); var isSink = ButtonHelper.GetClickStyle(BtnCustom); TbCode.Text = "<Button Height=\"30\"" + $"\nWidth=\"{BtnCustom.Width}\"" + $"\nContent=\"{BtnCustom.Content}\"" + (BtnCustom.Width < 60 ? $"\npu:ButtonHelper.WaitingContent=\"{{x:Null}}\"" : "") + (isSink == ClickStyle.Sink ? $"\npu:ButtonHelper.ClickStyle=\"Sink\"" : "") + (isWaiting ? $"\npu:ButtonHelper.IsWaiting=\"True\"" : "") + "\nFontFamily=\"{StaticResource FontAwesome}\"" + (buttonStyle == ButtonStyle.Standard ? "" : $"\npu:ButtonHelper.ButtonStyle=\"{buttonStyle}\"") + (buttonStyle == ButtonStyle.Standard ? $"\nBackground=\"{BtnCustom.Background.ToColor().ToHexString()}\"" : "") + (buttonStyle == ButtonStyle.Standard ? "" : $"\nBorderBrush=\"{BtnCustom.BorderBrush.ToColor().ToHexString()}\"") + (buttonStyle == ButtonStyle.Standard ? "" : $"\nForeground=\"{BtnCustom.Foreground.ToColor().ToHexString()}\"") + $"\npu:ButtonHelper.HoverBrush=\"{ButtonHelper.GetHoverBrush(BtnCustom).ToColor().ToHexString(false)}\"" + (cornerRadius == 0 ? "" : $"\npu:ButtonHelper.CornerRadius=\"{cornerRadius}\"") + " />"; }