我正在使用WCF开发Windows 8应用程序。为此,我创建了自己的控件。现在我需要另一个控件从第一个开始。那基本上可以吗?
在我的尝试中,我使用VS tempalte创建了第一个控件,默认情况下包含.cs和.xaml文件。第二个是普通的普通类,它只是从第一个继承而来。但是,只要第二个控件初始化,应用程序就会崩溃并显示错误消息“Parser internal error:Object writer'xClassNotDerivedFromElement'。[Line:2 Position:13]”
首先控制.cs:
namespace Reaction
{
public partial class ReactionGame : UserControl
{
public bool finished = false;
public bool winable = false;
public ReactionGame()
{
this.InitializeComponent();
}
public virtual void load()
{
// do all games actions (set up timers, etc)
}
public virtual void won()
{
// called when the game is won (free grafics, animate win stuff)
}
public virtual void lost()
{
// called when the game is lost (free grafics, animate loose stuff)
}
}
}
First Control XAML:
<UserControl
x:Class="Reaction.ReactionGame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Reaction"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid/>
</UserControl>
Second Control .cs(仅限):
namespace Reaction.ReactionGames
{
public class WhiteGame:ReactionGame
{
Windows.UI.Xaml.DispatcherTimer timer = null;
public WhiteGame()
{
this.InitializeComponent();
}
public override void load()
{
Windows.UI.Xaml.DispatcherTimer timer = new DispatcherTimer();
timer.Tick += timer_Tick;
timer.Interval = new TimeSpan(00, 0, 5);
timer.Start();
}
void timer_Tick(object sender, object e)
{
timer.Stop();
Rectangle rect = new Rectangle();
rect.Height = 200;
rect.Width = 200;
rect.Fill = new SolidColorBrush(Color.FromArgb(255, 105, 203, 44));
this.Content = rect;
winable = true;
}
public override void won()
{
MessageDialog msg = new MessageDialog("Gewonnen!");
msg.ShowAsync();
}
public override void lost()
{
}
}
}