WPF 事件处理
public class MyForm{
public System.Windows.Shapes.Rectangle m_rect;
private int m_width;
private int m_heigth;
private BitmapImage bitmig;
public MyForm()
{
this.m_rect.MouseDown += MinePane_MouseDown;
m_rect = new System.Windows.Shapes.Rectangle();
Uri uri = new Uri("Resources\\BITMAP10.BMP", UriKind.Relative);
bitmig=new BitmapImage(uri);
m_width = (int)bitmig.Width;
m_heigth = (int)(bitmig.Height / 16);
System.Windows.Media.Imaging.CroppedBitmap cb = new CroppedBitmap(bitmig,
new System.Windows.Int32Rect(0, 0, m_width, m_heigth));
m_rect.Fill =new ImageBrush(cb);
State = state.Normal;
}
public void MinePane_MouseDown(object sender,System.Windows.Input.MouseButtonEventArgs e)
{
System.Windows.Media.Imaging.CroppedBitmap cb = new CroppedBitmap(bitmig,
new System.Windows.Int32Rect(0,m_heigth*15, m_width, m_heigth));
m_rect.Fill = new ImageBrush(cb);
}
}
在 System.Windows.Markup.XamlParseException 中第一次偶然出现的“PresentationFramework.dll”类型的异常
其他信息: 无法创建在程序集“我的扫雷, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中定义的“MainForm”的实例。 调用的目标发生了异常。 标记文件中“MainForm.xaml”行1位置9处的错误。
这个问题出在哪里? --------------------编程问答-------------------- 可能你修改了xaml的内容或者使用了中文的文件名。
默认创建的应该是可以的 --------------------编程问答-------------------- public class MyForm
{
public System.Windows.Shapes.Rectangle m_rect;
private int m_width;
private int m_heigth;
private BitmapImage bitmig;
public MyForm()
{
this.m_rect.MouseDown += MinePane_MouseDown;
m_rect = new System.Windows.Shapes.Rectangle();
Uri uri = new Uri("Resources\\BITMAP10.BMP", UriKind.Relative);
bitmig=new BitmapImage(uri);
m_width = (int)bitmig.Width;
m_heigth = (int)(bitmig.Height / 16);
System.Windows.Media.Imaging.CroppedBitmap cb = new CroppedBitmap(bitmig,
new System.Windows.Int32Rect(0, 0, m_width, m_heigth));
m_rect.Fill =new ImageBrush(cb);
State = state.Normal;
}
public void MinePane_MouseDown(object sender,System.Windows.Input.MouseButtonEventArgs e)
{
System.Windows.Media.Imaging.CroppedBitmap cb = new CroppedBitmap(bitmig,
new System.Windows.Int32Rect(0,m_heigth*15, m_width, m_heigth));
m_rect.Fill = new ImageBrush(cb);
}
}
红色部分你写错了,应该如下这样才对的。
this.m_rect.MouseDown +=new MouseButtonEventHandler(MinePane_MouseDown); --------------------编程问答-------------------- 不懂你的xaml中行1是什么内容。你连xaml一行内容都不贴出来,想让人胡乱猜什么呢? --------------------编程问答-------------------- 不过基本上可以判读,你的代码中根本没有什么 MainForm 这个class的! --------------------编程问答-------------------- this.m_rect.MouseDown += MinePane_MouseDown;
这在.net 4中是合法的. --------------------编程问答-------------------- 除
补充:.NET技术 , .NET Framework