Mattiemus
Topic Author
Posts: 2
Joined: 21 Dec 2012, 20:59

Unable to use XAML player

24 Dec 2012, 00:35

Hello, I have started working on my gui using expression blend however I am having a problem when using the noesis xaml player, I am getting an error when attempting to run my .xaml files.

The error
Image

MainWindow.xaml
<Window
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="VitareGraphicInterface.MainWindow"
 x:Name="Window"
 Title="MainWindow"
 Width="640" Height="480">

 <Grid x:Name="LayoutRoot">
  <Button Content="Button" HorizontalAlignment="Right" Height="40" Margin="0,0,8,8" VerticalAlignment="Bottom" Width="128" Style="{DynamicResource LoginButton}"/>
  <TextBox Height="39" Margin="18,0,153,9" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Style="{DynamicResource passwordBox}"/>
 </Grid>
</Window>
Resources.xaml
<ResourceDictionary
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 <Style x:Key="LoginButton" TargetType="{x:Type Button}">
  <Setter Property="Background">
   <Setter.Value>
    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
     <GradientStop Color="#FFB7EAFF" Offset="0"/>
     <GradientStop Color="#FF97D5EF" Offset="0.514"/>
     <GradientStop Color="#FF97D5EF" Offset="1"/>
     <GradientStop Color="#FFB7EAFF" Offset="0.498"/>
    </LinearGradientBrush>
   </Setter.Value>
  </Setter>
 </Style>
 <Style x:Key="passwordBox" TargetType="{x:Type TextBox}">
  <Setter Property="Background" Value="#FFCCA314"/>
 </Style>
 <!-- Resource dictionary entries should be defined here. -->
</ResourceDictionary>
App.xaml
<Application
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="VitareGraphicInterface.App"
 StartupUri="MainWindow.xaml">
 <Application.Resources>
  <!-- Resources scoped at the Application level should be defined here. -->
  <ResourceDictionary>
   <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Resources.xaml"/>
   </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
 </Application.Resources>
</Application>
I can however get the window to display by removing the errornous x:Class="VitareGraphicInterface.MainWindow" however this causes the window to become black and no elements are displayed.

Any help would be appreciated!

Cheers,
Matt
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Unable to use XAML player

24 Dec 2012, 11:31

Hi Mattiemus,

When you design an application with Expression Blend, the tool creates automatically an App.xaml and MainWindow.xaml that are binded to code behind classes, specified by the x:Class property. So if you don't remove that property, you should provide corresponding classes in C++.

For your example, you should create an Application derived class that defines the TypeId metadata with the value "VitareGraphicInterface.App" as it appears in the App.xaml:
#include <NsGui/Application.h>
#include <NsCore/TypeId.h>
#include <NsCore/ReflectionImplement.h>

class VitareApp: public Noesis::Gui::Application
{
    NS_IMPLEMENT_INLINE_REFLECTION(VitareApp, Noesis::Gui::Application)
    {
        NsMeta<Noesis::Core::TypeId>("VitareGraphicInterface.App");
    }
};
You should also create a Window derived class that defines the TypeId metadata with the value "VitareGraphicInterface.MainWindow" as it appears in the MainWindow.xaml:
#include <NsGui/Window.h>
#include <NsCore/TypeId.h>
#include <NsCore/ReflectionImplement.h>

class VitareMainWindow: public Noesis::Gui::Window
{
    NS_IMPLEMENT_REFLECTION(VitareMainWindow, Noesis::Gui::Window)
    {
        NsMeta<Noesis::Core::TypeId>("VitareGraphicInterface.MainWindow");
    }
};
And finally, register those components in the ComponentFactory so NoesisGUI framework knows how to create them:
#include <NsCore/Package.h>
#include "VitareApp.h"
#include "VitareMainWindow.h"

NS_REGISTER_REFLECTION(Vitare, GraphicInterface)
{
    NS_REGISTER_COMPONENT(VitareApp)
    NS_REGISTER_COMPONENT(VitareMainWindow)
}

NS_INIT_PACKAGE(Vitare, GraphicInterface)
{
}

NS_SHUTDOWN_PACKAGE(Vitare, GraphicInterface)
{
}
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unable to use XAML player

24 Dec 2012, 12:17

By the way, these steps are fully described in the Tutorial 5: Building an application that comes with the NoesisGUI SDK.

Thanks.
 
Mattiemus
Topic Author
Posts: 2
Joined: 21 Dec 2012, 20:59

Re: Unable to use XAML player

24 Dec 2012, 15:37

Thanks for the fast reply,
I have managed to get it working now, however it appears that the window was still appearing black as I was referencing styles (Style="{DynamicResource LoginButton}") in the window.
 
michael1220
Posts: 3
Joined: 24 Dec 2012, 13:14
Location: Vienna

Re: Unable to use XAML player

24 Dec 2012, 16:02

By the way, these steps are fully described in the Tutorial 5: Building an application that comes with the NoesisGUI SDK.

Thanks.
Where are the Tutorials located?
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unable to use XAML player

24 Dec 2012, 19:37

Where are the Tutorials located?
The documentation is located at index.html, in the root directory after unzipping the .7z package.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Unable to use XAML player

28 Dec 2012, 00:23

Thanks for the fast reply,
I have managed to get it working now, however it appears that the window was still appearing black as I was referencing styles (Style="{DynamicResource LoginButton}") in the window.
The window is black because the Background property of the Window is not set, and the default value is null. If you want your window to have a color or gradient background you should set the Background property accordingly.

The problem that makes your controls not visible is because in NoesisGUI there is no default style to rely on for the properties that are not set in your Style. So when you set the Style property of a Control, the Style object must have a Setter for the Template property with a valid ControlTemplate defined or be BasedOn a Style with the Template property correctly set. Otherwise the Control would not have a visual tree to be rendered.

;)

Who is online

Users browsing this forum: Google [Bot] and 73 guests