Windows 鼠标文件格式
Windows 的鼠标文件格式有两种,一种是静态文件(.cur),另一种是动态文件(.ani)。
其中 cur 文件本身我们操作系统就有,大家可以通常在 C:\Windows\Cursors 这个目录下面找到。
示例代码
XAML
<Window x:Class="NotifyData.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NotifyData"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Vertical">
<ProgressBar Name="myProgressBar" Height="20" Maximum="100" Minimum="0" Value="{Binding Count}"></ProgressBar>
</StackPanel>
</Window>Code language: HTML, XML (xml)
C# 代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace NotifyData
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MyViewModel myViewModel = new MyViewModel();
public MainWindow()
{
InitializeComponent();
myViewModel.Count = 50;
this.myProgressBar.DataContext = myViewModel;
}
}
public class MyViewModel: INotifyPropertyChanged
{
private int count;
public int Count
{
get
{
return count;
}
set
{
count = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}Code language: HTML, XML (xml)
02-后台异步改变数据源
public partial class MainWindow : Window
{
public MyViewModel myViewModel = new MyViewModel();
public MainWindow()
{
InitializeComponent();
myViewModel.Count = 50;
this.myProgressBar.DataContext = myViewModel;
new Thread(new ThreadStart(Deal)) { IsBackground = true }.Start();
}
private void Deal()
{
while (true)
{
myViewModel.Count++;
Thread.Sleep(200);
}
}
}
03-多个窗体绑定同一个数据源
namespace NotifyData
{
public static class DataSource
{
public static MyViewModel myViewModel = new MyViewModel();
}
}
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
this.myProgressBar.DataContext = DataSource.myViewModel;
}
}
07-数据源是一个字典绑定多个窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace NotifyData
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow(bool b)
{
InitializeComponent();
}
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 5; i++)
{
DataSource.myViewModel.Count.Add(i, i);
}
var progress0 = new ProgressBar();
progress0.Maximum = 100;
progress0.Minimum = 0;
progress0.Height = 20;
Binding bind0 = new Binding()
{
Source = DataSource.myViewModel,
Path = new PropertyPath("Count[0]")
};
BindingOperations.SetBinding(progress0, ProgressBar.ValueProperty, bind0);
this.myStack.Children.Add(progress0);
for (int i = 1; i < 5; i++)
{
MainWindow w1 = new MainWindow(true);
var progress = new ProgressBar();
progress.Maximum = 100;
progress.Minimum = 0;
progress.Height = 20;
Binding bind = new Binding()
{
Source = DataSource.myViewModel,
Path = new PropertyPath("Count[" + i + "]")
};
BindingOperations.SetBinding(progress, ProgressBar.ValueProperty, bind);
w1.myStack.Children.Add(progress);
w1.Show();
}
new Thread(new ThreadStart(Deal)) { IsBackground = true }.Start();
}
private Random random = new Random();
private void Deal()
{
while (true)
{
int index = random.Next(0, DataSource.myViewModel.Count.Count);
DataSource.myViewModel.Count[index]++;
DataSource.myViewModel.Count = new Dictionary<int, int>(DataSource.myViewModel.Count);
Thread.Sleep(20);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
public class MyViewModel : INotifyPropertyChanged
{
private Dictionary<int, int> count;
public Dictionary<int, int> Count
{
get
{
if (count == null)
{
count = new Dictionary<int, int>();
}
return count;
}
set
{
count = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
08-窗体的标题动态绑定
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace NotifyData
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow(bool b)
{
InitializeComponent();
}
public MainWindow()
{
InitializeComponent();
// 准备数据源
for (int i = 0; i < 5; i++)
{
DataSource.myViewModel.Count.Add(i, i);
DataSource.myViewModel.Name.Add(i, i.ToString());
}
// 主窗体动态添加控件 并且绑定
var progress0 = new ProgressBar();
progress0.Maximum = 100;
progress0.Minimum = 0;
progress0.Height = 20;
Binding bind0 = new Binding()
{
Source = DataSource.myViewModel,
Path = new PropertyPath("Count[0]")
};
BindingOperations.SetBinding(progress0, ProgressBar.ValueProperty, bind0);
this.myStack.Children.Add(progress0);
BindingOperations.SetBinding(this, Window.TitleProperty, new Binding() { Source = DataSource.myViewModel, Path = new PropertyPath("Name[0]") });
// 添加多个子窗体(也是主窗体)
for (int i = 1; i < 5; i++)
{
MainWindow w1 = new MainWindow(true);
var progress = new ProgressBar();
progress.Maximum = 100;
progress.Minimum = 0;
progress.Height = 20;
Binding bind = new Binding()
{
Source = DataSource.myViewModel,
Path = new PropertyPath("Count[" + i + "]")
};
BindingOperations.SetBinding(progress, ProgressBar.ValueProperty, bind);
BindingOperations.SetBinding(w1, Window.TitleProperty, new Binding() { Source = DataSource.myViewModel, Path = new PropertyPath("Name[" + i + "]") });
w1.myStack.Children.Add(progress);
w1.Show();
}
new Thread(new ThreadStart(Deal)) { IsBackground = true }.Start();
}
private Random random = new Random();
private void Deal()
{
while (true)
{
int index = random.Next(0, DataSource.myViewModel.Count.Count);
DataSource.myViewModel.Count[index]++;
DataSource.myViewModel.Count = new Dictionary<int, int>(DataSource.myViewModel.Count);
Thread.Sleep(20);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
public class MyViewModel : INotifyPropertyChanged
{
private Dictionary<int, int> count;
public Dictionary<int, int> Count
{
get
{
if (count == null)
{
count = new Dictionary<int, int>();
}
return count;
}
set
{
count = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count"));
}
}
private Dictionary<int, string> name;
public Dictionary<int, string> Name
{
get
{
if (name == null)
{
name = new Dictionary<int, string>();
}
return name;
}
set
{
name = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}