有一个类:
public class GLine : Button
{
public int x, y;
Game game;
public GLine(int x, int y)
{
this.x = x;
this.y = y;
Grid.SetRow(this, y);
Grid.SetColumn(this, x);
DataContextChanged += GLine_DataContextChanged;
}
private void GLine_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
game = (Game)DataContext;
Click += game.PlayerClick;
}
}
如何使用放置该对象的 UserControl 的标记中描述的样式设置此类的对象?
TargetType = "Button" - 不起作用。
只需提供类名,不要忘记 XAML 命名空间,例如: