-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: A few questions about some features
Hi,
Sorry for the very late answer
I tried your sample and, once added serialization code (see below) to the InventoryTileModel class, it works as expected, inside XamlPlayer and in a external application.
Can I have a look at your serialization code? Mine looks like this:
How do you initialize NoesisGUI and load this xaml in your application?
Have you registered the component in the ComponentFactory before loading the xaml?
Anything you try in XamlPlayer should work the same way in your application, otherwise we have a bug in our code.
Sorry for the very late answer
I tried your sample and, once added serialization code (see below) to the InventoryTileModel class, it works as expected, inside XamlPlayer and in a external application.
Can I have a look at your serialization code? Mine looks like this:
Code: Select all
void Serialize(Noesis::Core::SerializationData* data) const
{
data->Serialize("ItemID", _itemID);
data->Serialize("Quantity", _quantity);
}
void Unserialize(Noesis::Core::UnserializationData* data, NsUInt32 version)
{
data->Unserialize("ItemID", _itemID);
data->Unserialize("Quantity", _quantity);
}
Have you registered the component in the ComponentFactory before loading the xaml?
Code: Select all
extern "C" NS_DLL_EXPORT void NsRegisterReflection(ComponentFactory* factory, NsBool registerComponents)
{
NS_REGISTER_COMPONENT(InventoryTileModel)
}
Re: A few questions about some features
For my integration purpose, I've stopped creating data model from my xaml files. Therefore I don't have that problem anymore, but I'm looking at my code right now and it seems the Serialize/Unserialize methods are the same and the way I'm loading it from my application is strictly the same as presented in the tutorials, that's quite weird.
However, I'm facing a similar problem now. I have a UserControl with two properties I'd like to be able to set in my Xaml file.
That leads to a crash in my application when trying to load the xaml file containing that line. Not mentioning Value in the line allows to load the Xaml file, with Value equals to its default value. I've followed the UserControl tutorial and read the DependencyProperty documentation and I don't see what I'm missing.
I figured out the NsProp("Value", [Getter], [Setter]) line is not required if I don't want to use particular accessor/mutator couple. Am I right?
Thanks!
However, I'm facing a similar problem now. I have a UserControl with two properties I'd like to be able to set in my Xaml file.
Code: Select all
[...]
static const Noesis::Gui::DependencyProperty* ValueProperty;
NS_IMPLEMENT_INLINE_REFLECTION([i][UserControl][/i], Noesis::Gui::UserControl)
{
NsMeta<Noesis::Core::TypeId>("[i][UserControl][/i]");
Noesis::Core::Ptr<Noesis::Gui::UIElementData> data = NsMeta<Noesis::Gui::UIElementData>(Noesis::Core::TypeOf<SelfClass>());
// {TODO} Should be available from Xaml
data->RegisterProperty<NsUInt32>(
ValueProperty,
"Value",
Noesis::Gui::FrameworkPropertyMetadata::Create(5, Noesis::Gui::FrameworkOptions_None));
[...]
Code: Select all
<[i][UserControl][/i]Value="10"/>
I figured out the NsProp("Value", [Getter], [Setter]) line is not required if I don't want to use particular accessor/mutator couple. Am I right?
Thanks!
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: A few questions about some features
I suppose that every reference to in the code you posted refers to your user control class name
Apart from that, when you are creating your own user control, one important thing you can't miss is to specify the xaml source when registering the class reflection:
Otherwise, when referencing the control in another xaml, it won't be able to load the associated xaml.
Anyway, if you are getting a crash you should be able to generate a crash dump. Please create a ticket in our bugtracker and attach the dump so we can investigate the origin of the crash.
Code: Select all
[i][UserControl][/i]
Apart from that, when you are creating your own user control, one important thing you can't miss is to specify the xaml source when registering the class reflection:
Code: Select all
[...]
static const Noesis::Gui::DependencyProperty* ValueProperty;
NS_IMPLEMENT_INLINE_REFLECTION(MyUserControl, Noesis::Gui::UserControl)
{
NsMeta<Noesis::Core::TypeId>("MyUserControl");
Noesis::Core::Ptr<Noesis::Gui::UIElementData> data = NsMeta<Noesis::Gui::UIElementData>(Noesis::Core::TypeOf<SelfClass>());
NsString source = "assets/UI/UserControls/MyUserControl.xaml";
data->OverrideMetadata<NsString>(
UserControl::SourceProperty,
"Source",
Noesis::Gui::FrameworkPropertyMetadata::Create(source,
Noesis::Gui::FrameworkOptions_None));
data->RegisterProperty<NsUInt32>(
ValueProperty,
"Value",
Noesis::Gui::FrameworkPropertyMetadata::Create((NsUInt32)5,
Noesis::Gui::FrameworkOptions_None));
}
[...]
Anyway, if you are getting a crash you should be able to generate a crash dump. Please create a ticket in our bugtracker and attach the dump so we can investigate the origin of the crash.
Re: A few questions about some features
Oops yes, that's what I meant
I did not forget to specify the source. Every files seem to be parsed correctly by the BuildTool, but when calling Noesis::Gui::GUI::LoadXaml (after a dozen other internal Noesis calls), the application crashes:
Unhandled exception at 0x000007FEEAEA4101 (Noesis.dll) in Dual_d.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Removing the Value="10" part solves the problem.
I did not forget to specify the source. Every files seem to be parsed correctly by the BuildTool, but when calling Noesis::Gui::GUI::LoadXaml (after a dozen other internal Noesis calls), the application crashes:
Unhandled exception at 0x000007FEEAEA4101 (Noesis.dll) in Dual_d.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Removing the Value="10" part solves the problem.
Re: A few questions about some features
In order to provide an actual integration test, I've used your DirectX11 Integration tutorial with a simple user control.
UserControlTest.h:
UserControlTest.cpp:
devel_sample.xaml
usercontroltest.xaml:
Integration code:
I have no problem building each Xaml file and it works just fine in the XamlPlayer. However, the application crashes when reaching
exactly as it does in my actual application.
I must be missing something here. I think I've followed exactly what is written in the UserControl tutorial. According to the page about DependencyProperty, I shouldn't have to write the NsProp line, but not putting it makes the XamlPlayer throwing a "Test not recognized error".
What am I missing?
Thank you for your help.
UserControlTest.h:
Code: Select all
#pragma once
#include <NsGui/UserControl.h>
#include <NsGui/FrameworkPropertyMetadata.h>
#include <NsGui/UIElementData.h>
namespace NQ
{
namespace Gui
{
class UserControlTest : public Noesis::Gui::UserControl
{
public:
NsInt32 GetTest() const { return Noesis::Gui::DependencyObject::GetValue<NsInt32>(TestProperty); }
void SetTest(NsInt32 in) { Noesis::Gui::DependencyObject::SetValue<NsInt32>(TestProperty, in); }
static const Noesis::Gui::DependencyProperty* TestProperty;
private:
NS_IMPLEMENT_INLINE_REFLECTION(UserControlTest, Noesis::Gui::UserControl)
{
NsMeta<Noesis::Core::TypeId>("UserControlTest");
NsProp("Test", &UserControlTest::GetTest, &UserControlTest::SetTest);
NsString source = "usercontroltest.xaml";
Noesis::Core::Ptr<Noesis::Gui::UIElementData> data = NsMeta<Noesis::Gui::UIElementData>(Noesis::Core::TypeOf<SelfClass>());
data->RegisterProperty<NsInt32>(
TestProperty,
"Test",
Noesis::Gui::FrameworkPropertyMetadata::Create((NsInt32)0, Noesis::Gui::FrameworkOptions_None));
data->OverrideMetadata<NsString>(
UserControl::SourceProperty,
"Source",
Noesis::Gui::FrameworkPropertyMetadata::Create(source, Noesis::Gui::FrameworkOptions_None));
}
};
}
}
Code: Select all
#include "UserControlTest.h"
const Noesis::Gui::DependencyProperty* NQ::Gui::UserControlTest::TestProperty;
Code: Select all
<Border
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Root"
Background="#CC000000">
<UserControlTest Test="220891"/>
</Border>
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="UserControlTest" x:Name="ROOT_UserControlTest">
<Border HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding Test, ElementName=ROOT_UserControlTest}"/>
</Border>
</UserControl>
Code: Select all
SetupKeyMap();
Noesis::Gui::GUI::InitDirectX11(g_pd3dDevice, ErrorHandler);
Noesis::Gui::GUI::AddResourceProvider(".");
NsRegisterReflection(0, true);
Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("devel_sample.xaml");
g_XamlRenderer = Noesis::GUI::CreateRenderer(xaml.GetPtr());
g_XamlRenderer->SetSize(g_Width, g_Height);
g_XamlRenderer->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_PPAA);
Code: Select all
Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("devel_sample.xaml");
I must be missing something here. I think I've followed exactly what is written in the UserControl tutorial. According to the page about DependencyProperty, I shouldn't have to write the NsProp line, but not putting it makes the XamlPlayer throwing a "Test not recognized error".
What am I missing?
Thank you for your help.
Re: A few questions about some features
What kind of crashing are you getting. Is the ErrorHandler being invoked with an error description?I have no problem building each Xaml file and it works just fine in the XamlPlayer. However, the application crashes when reachingexactly as it does in my actual application.Code: Select allPtr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("devel_sample.xaml");
Re: A few questions about some features
Also, is the NsRegisterReflection properly implemented? Could you paste it here? I don't see it in the sources you posted above.
More questions, does the code in our UserControl Tutorial work properly? (adapting it to v1.2, because that code is still for v1.1... sorry for that)
Thanks!
More questions, does the code in our UserControl Tutorial work properly? (adapting it to v1.2, because that code is still for v1.1... sorry for that)
Thanks!
Re: A few questions about some features
NsRegisterReflection implementation:
Testing the tutorial right now...
Code: Select all
void NsRegisterReflection(Noesis::Core::ComponentFactory* factory, NsBool registerComponents)
{
NS_REGISTER_COMPONENT(NQ::Gui::UserControlTest);
}
Re: A few questions about some features
Also, please, place a breakpoint in the ErrorHandler. It should be getting invoked with a description about the error that is happening.
Re: A few questions about some features
I've tried the UserControl tutorial in the application unsuccessfully. I've pretty much copy-pasted what alreay existed in the tutorial and it got compiled almost immediatly (some namespace issues here and there). However, the result is the same: the application crashes at:
and did not enter the ErrorHandler function.
Again, the xaml files got built without any error, I did not forget the NsRegisterReflection function...
Code: Select all
Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("sample.xaml");
Again, the xaml files got built without any error, I did not forget the NsRegisterReflection function...
Who is online
Users browsing this forum: Google [Bot] and 6 guests