1

嗨,我从这个位置使用 WpfInterop NuGet 插件https://gitlab.com/MarcStan/MonoGame.Framework.WpfInterop/ 我按照自述文件中的方式完成了所有操作,但它不会加载到我的设计器中。

它总是说“无法创建“Game1”的实例(从德语翻译)并且也不会编译。

我已经尝试了一个新项目,但结果仍然相同。使用其他窗口也不起作用,即使生成新的 Game 类也无济于事。

我的 XAML 文件:

<Window x:Class="MapEditor.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:MapEditor"
    mc:Ignorable="d"
    Title="MainWindow" Height="479.369" Width="767.693" WindowStartupLocation="CenterScreen">
<Grid Margin="0,0,2,-1" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
    <Grid.BindingGroup>
        <BindingGroup/>
    </Grid.BindingGroup>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="377*"/>
        <ColumnDefinition Width="0*"/>
        <ColumnDefinition/>
        <ColumnDefinition Width="380*"/>
    </Grid.ColumnDefinitions>

    <Menu Height="21" VerticalAlignment="Top" Grid.ColumnSpan="4" Grid.IsSharedSizeScope="True" Foreground="Black">
        <Menu.Background>
            <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlColorKey}}"/>
        </Menu.Background>
        <MenuItem Height="21" Width="45" AllowDrop="True" Header="Datei" >
            <MenuItem Header="Test"/>
        </MenuItem>
        <MenuItem Header="Bearbeiten" Width="72"/>
    </Menu>
    <ListView HorizontalAlignment="Left" Margin="10,26,0,10" Width="165">
        <ListView.View>
            <GridView>
                <GridViewColumn/>
            </GridView>
        </ListView.View>
    </ListView>
    <ListView Margin="0,26,10,10" Grid.Column="3" HorizontalAlignment="Right" Width="165">
        <ListView.View>
            <GridView>
                <GridViewColumn/>
            </GridView>
        </ListView.View>
    </ListView>
    <local:Game1 Width="50" Height="50"/>
</Grid>

编辑:我的 Game1 类

using MapEditor.mapClasses;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Framework.WpfInterop;
using MonoGame.Framework.WpfInterop.Input;


namespace MapEditor
{
/// <summary>
/// This is the main type for your game.
/// </summary>
/// 

public class Game1 : WpfGame
{

    private IGraphicsDeviceService _graphicsDeviceManager;
    private WpfKeyboard _keyboard;
    private WpfMouse _mouse;

    protected override void Initialize()
    {
        // must be initialized. required by Content loading and rendering (will add itself to the Services)
        _graphicsDeviceManager = new WpfGraphicsDeviceService(this);

        // wpf and keyboard need reference to the host control in order to receive input
        // this means every WpfGame control will have it's own keyboard & mouse manager which will only react if the mouse is in the control
        _keyboard = new WpfKeyboard(this);
        _mouse = new WpfMouse(this);

        // must be called after the WpfGraphicsDeviceService instance was created
        base.Initialize();

        // content loading now possible
    }

    protected override void Update(GameTime time)
    {
        // every update we can now query the keyboard & mouse for our WpfGame
        var mouseState = _mouse.GetState();
        var keyboardState = _keyboard.GetState();
    }

    protected override void Draw(GameTime time)
    {
    }
  }
}
4

0 回答 0