XAML from GamePage.xaml not shown.

Hello,
In my last Apps with MonoGame i simply could write xaml code in the GamePage.xaml and it was displayed above the MonoGame Stuff. <- This was easy and I liked it.

But here is my problem: XAML doesn’t show up anymore. Even if I create a new WP8.1 project and simply add a button to the grid from the GamePage.xaml nothing is visible.

Please tell me where I should put my xaml code?

I’m using latest MonoGame dev build (3.3) … vs2013 with all updates … lumia 1020

Best regards,
Faic

Is there a DrawingSurface or a DrawingSurfaceBackgroundGrid in your XAML?

With the MonoGame WP8.1 template the only xaml I got is a SwapChainBackgroundPanel with a grid inside:

<SwapChainBackgroundPanel
    x:Class="TreasureHunter.GamePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TreasureHunter"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>

    </Grid>

</SwapChainBackgroundPanel>

Edit: This is the GamePage.xaml
Edit2: I tried everything. Xaml code is definitely not shown in the GamePage.xaml file. But where should I put the xaml code ?!?

Ok, I spend several days wasting my time to get it to work. So please tell me where to put my XAML code, this can’t be that difficult, otherwise MonoGame is heading in a completely wrong direction.

Example: I want to display a <Button /> … where do I have to put this code so that I can see the button on my phone?

This works for me:

 <phone:PhoneApplicationPage
x:Class="X.UnitTest.WP8.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Landscape" Orientation="Landscape"
shell:SystemTray.IsVisible="False">
<DrawingSurfaceBackgroundGrid x:Name="XnaSurface" Background="Transparent">
<MediaElement IsHitTestVisible="False" x:Name="XnaMediaElement" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="TEST APP" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="Unit Test" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock x:Name="label" Text="Tests running..." HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</DrawingSurfaceBackgroundGrid>
</phone:PhoneApplicationPage>

Thanks for you reply : )
Are you on the development branch version 3.3?

If I create a new WP8.1 Monogame project, there is no <Phone:PhoneApplicationPage ...
Only the App.xaml and the MainPage.xaml which is only a SwapChainBackgroundPanel and not a DrawingSurfaceBackgroundGrid.

Sorry, I totally missed that you are using the WinRT version. Havent tried that one.

No problem. But I’m still not able to show xaml. Is there really no one who can tell me how this works in Version 3.3 ?!?

Common guys, I really don’t want to quit this project for such a reason.

In Version 3.3 for WP8.1: Where do I have to put my xaml code so that a <Button/> for example is visible?!?

could you post GamePage.xaml.cs ?

<SwapChainBackgroundPanel
    x:Class="Game2.GamePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Game2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Button Content="I can't see this button"/>
    </Grid>
</SwapChainBackgroundPanel>

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using MonoGame.Framework;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace Game2
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class GamePage : SwapChainBackgroundPanel
    {
        readonly Game1 _game;
        public GamePage()
        {
            this.InitializeComponent();
        }

        public GamePage(string launchArguments)
        {
            _game = XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, this);
        }
    }
}

Simply create a new WP8.1 Monogame 3.3 Template Project and try to add xaml code. I found no way my xaml code is visible.

This is something I saw a few days ago and I thought it was weird. There are two constructors, one calls InitializeComponent and the other one does not. Could you check which one is being called, and putting InitializeComponent before Create if it’s the second one?

2 Likes

YOU ARE MY HERO !!!

Yeah, simply add this.InitializeComponent(); to the second constructor and everything works fine.

… so someone should fix the template.

public sealed partial class GamePage : SwapChainBackgroundPanel
    {
        readonly Game1 _game;
        public GamePage() //Constructor is never called
        {
            this.InitializeComponent();
        }

        public GamePage(string launchArguments)
        {
             // Here was a InitializeComponent missing.
             this.InitializeComponent();
            _game = XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, this);
        }
    }
}

thanks :slight_smile:

I don’t know if this is a bug or a feature, the one who built two constructors probably had a good reason to do so (I don’t know, maybe performance reasons?)