我想設計一個系統界面,我有不同的控件(矩形)一個接一個地動畫(發光或發光),並將消息發送到隊列,因爲他們動畫 - 我是C#和WPF所以不太清楚如何appoach這個 - 任何出發點?使用WPF事件觸發事件
編輯:
感謝您的例子 - 雖然不能完全理解它,我想出了以下,但仍然有一些問題:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using System.ComponentModel;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
// public partial class MainWindow : Window
//{
// public MainWindow()
//{
// InitializeComponent();
//DataContext = this;
//}
//}
public class Glow : INotifyPropertyChanged
{
private double m_glowSize;
public event PropertyChangedEventHandler PropertyChanged;
public double GlowSize
{
get { return m_glowSize; }
set
{
m_glowSize = value;
NotifyPropertyChanged("GlowSize");
}
}
public void Window()
{
InitializeComponent();
DataContext = this;
}
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
Canvas canvas = sender as Canvas;
if (canvas != null)
{
Point mousePosition = e.GetPosition(canvas);
GlowSize = 20 * (mousePosition.X/canvas.ActualWidth);
}
}
private void NotifyPropertyChanged(string s)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(s));
}
}
}
問題似乎是這個塊:
public void Window()
{
InitializeComponent();
DataContext = this;
}
DataContext = this;
是做什麼的,我該如何正確設置它?
閱讀關於觸發器,數據觸發器和事件觸發器假設它們是開始的基礎知識。另外,看看ObservableCollection和INotifyPropertyChanged這些東西在未來會有幫助。 – 2010-08-29 14:09:20