public void AddWindowButton(string toolTip, PackIconBase icon, Action onClick) { var button = new Button { Content = icon, ToolTip = toolTip }; button.Click += (o, s) => onClick(); AddWindowButton(button); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { StackPanel stackPanel = new StackPanel() { Orientation = Orientation.Horizontal }; PackIconBase icon = null; string text = ""; ResourceManager resourceManager = new ResourceManager(typeof(Properties.Resources)); GitHubRelease release = (GitHubRelease)value; switch (release.ReleaseTimeType) { case GitHubReleaseTimeTypes.OLD: icon = new PackIconMaterial() { Kind = PackIconMaterialKind.History }; text = resourceManager.GetString("DowngradeString"); break; case GitHubReleaseTimeTypes.CURRENT: icon = new PackIconOcticons() { Kind = PackIconOcticonsKind.Tools }; text = resourceManager.GetString("RepairString"); break; case GitHubReleaseTimeTypes.NEW: icon = new PackIconOcticons() { Kind = PackIconOcticonsKind.DesktopDownload }; text = resourceManager.GetString("UpgradeString"); break; } icon.Width = 20; icon.Height = double.NaN; icon.Margin = new System.Windows.Thickness(5, 0, 10, 0); icon.VerticalAlignment = System.Windows.VerticalAlignment.Center; stackPanel.Children.Add(icon); stackPanel.Children.Add(new TextBlock(new Run(text)) { FontSize = 12, VerticalAlignment = System.Windows.VerticalAlignment.Center }); return(stackPanel); }
public void AddWindowButton(string toolTip, PackIconBase icon, Action onClick) { if (Window == null) { return; } var button = new Button { Content = icon, ToolTip = toolTip }; button.Click += (o, s) => onClick(); Window.AddWindowButton(button); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(null); } Brush foregroundBrush = App.Current.TryFindResource("IdealForegroundColorBrush") as Brush; PackIconBase iconBase = ((PackIconBase)value); string iconDataStr = iconBase.GetType().GetProperty("Data").GetValue(iconBase, null) as string; Geometry iconGeometry = Geometry.Parse(iconDataStr); GeometryDrawing iconGeometryDrawing = new GeometryDrawing(foregroundBrush, new Pen(foregroundBrush, 1), iconGeometry); return(iconGeometryDrawing); }
/// <summary> /// nuget套件 MahApps.Metro.IconPacks /// 三种雪花样式,下降加旋转动画 /// </summary> /// <param name="panel"></param> void StartSnowing(Canvas panel) { Random random = new Random(); Task.Factory.StartNew(new Action(() => { for (int j = 0; j < 25; j++) { Thread.Sleep(j * 100); Dispatcher.Invoke(new Action(() => { int snowCount = random.Next(0, 10); for (int i = 0; i < snowCount; i++) { int width = random.Next(10, 20); PackIconBase pack = null; int snowType = random.Next(3); //三种雪花 switch (snowType) { case 0: pack = new PackIconFontAwesome() { Kind = PackIconFontAwesomeKind.SnowflakeRegular }; break; case 1: pack = new PackIconMaterial() { Kind = PackIconMaterialKind.Snowflake }; break; case 2: pack = new PackIconModern() { Kind = PackIconModernKind.Snowflake }; break; default: break; } pack.Width = width; pack.Height = width; pack.Foreground = Brushes.White; pack.BorderThickness = new Thickness(0); pack.RenderTransform = new RotateTransform(); int left = random.Next(0, (int)panel.ActualWidth); Canvas.SetLeft(pack, left); panel.Children.Add(pack); int seconds = random.Next(20, 30); DoubleAnimationUsingPath doubleAnimation = new DoubleAnimationUsingPath() //下降动画 { Duration = new Duration(new TimeSpan(0, 0, seconds)), RepeatBehavior = RepeatBehavior.Forever, PathGeometry = new PathGeometry(new List <PathFigure>() { new PathFigure(new Point(left, 0), new List <PathSegment>() { new LineSegment(new Point(left, panel.ActualHeight), false) }, false) }), Source = PathAnimationSource.Y }; pack.BeginAnimation(Canvas.TopProperty, doubleAnimation); DoubleAnimation doubleAnimation1 = new DoubleAnimation(360, new Duration(new TimeSpan(0, 0, 10))) //旋转动画 { RepeatBehavior = RepeatBehavior.Forever, }; pack.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation1); } })); } })); }