当我遇到我更喜欢以流畅的风格编程的WPF部分时,我将支持的扩展方法添加到个人实用程序集。
TaskbarItemInfo
ProgressValue
和
ProgressState
财产。此版本以标准的非流利方式编写。
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shell;
namespace TaskbarItemProgress
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
TaskbarItemInfo = new TaskbarItemInfo();
TaskbarItemInfo.ProgressValue = 0.5;
var stackPanel = new StackPanel();
Content = stackPanel;
var normalButton = new Button() { Content = "Normal" };
normalButton.Click += (s, e) =>
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
stackPanel.Children.Add(normalButton);
var pausedButton = new Button() { Content = "Paused" };
pausedButton.Click += (s, e) =>
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Paused;
stackPanel.Children.Add(pausedButton);
var errorButton = new Button() { Content = "Error" };
errorButton.Click += (s, e) =>
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Error;
stackPanel.Children.Add(errorButton);
var indeterminateButton = new Button() { Content = "Indeterminate" };
indeterminateButton.Click += (s, e) =>
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Indeterminate;
stackPanel.Children.Add(indeterminateButton);
var noneButton = new Button() { Content = "None" };
noneButton.Click += (s, e) =>
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
stackPanel.Children.Add(noneButton);
var increaseButton = new Button() { Content = "Increase" };
increaseButton.Click += (s, e) => TaskbarItemInfo.ProgressValue += 0.10;
stackPanel.Children.Add(increaseButton);
var decreaseButton = new Button() { Content = "Decrease" };
decreaseButton.Click += (s, e) => TaskbarItemInfo.ProgressValue -= 0.10;
stackPanel.Children.Add(decreaseButton);
}
}
}
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shell;
using FluentWpf;
namespace TaskbarItemProgress
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
TaskbarItemInfo = new TaskbarItemInfo();
TaskbarItemInfo.ProgressValue = 0.5;
Content = new StackPanel()
.AddChildren(
new Button() { Content = "Normal" }
.AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal),
new Button() { Content = "Paused" }
.AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Paused),
new Button() { Content = "Error" }
.AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Error),
new Button() { Content = "Indeterminate" }
.AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Indeterminate),
new Button() { Content = "None" }
.AddClick((s, e) => TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None),
new Button() { Content = "Increase" } .AddClick((s, e) => TaskbarItemInfo.ProgressValue += 0.10),
new Button() { Content = "Decrease" } .AddClick((s, e) => TaskbarItemInfo.ProgressValue -= 0.10));
}
}
}
fluent版本采用了两种扩展方法,
AddChildren
(而不是
Children.Add
)及
AddClick
(而不是
Click += ...
).
我保留我的个人隐私
FluentWpf
library on github
.