1

我正在使用 WCF 开发 Windows 8 应用程序。为此,我创建了自己的控件。现在我需要从第一个继承的另一个控件。这基本上可以吗?

在我的尝试中,我使用 VS tempalte 创建了第一个控件,默认情况下由 .cs 和 .xaml 文件组成。第二个是一个普通的普通类,它只是从第一个继承而来。但是,一旦第二个控件被初始化,应用程序就会崩溃并显示错误消息“解析器内部错误:对象编写器'xClassNotDerivedFromElement'。[行:2 位置: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)
        }
    }
}

第一个控制 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>

第二个控制 .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()
        {

        }
    }
}
4

0 回答 0