Namespace prefix not declared
Hello,
I am experimenting with NoesisGUI in C# with Unity, just following the first step guide right now and I have hit a snag with trying to show a secondary UserControl as described here:
https://www.noesisengine.com/docs/Gui.C ... aml-assets
So I have the auto-generated main view
XAML
C#
And a custom control (made through tools -> NoesisGUI -> Create -> UserControl
XAML
C#
The only changes from the auto generated code are:
- I changed the namespace for 'CrewInfo' from 'Testing' to 'Plundersea'
- I added '<local:CrewInfo />' to PlunderseaMainView.xaml
Now it seems CrewInfo is not able to be found because I get an error "Namespace prefix not declared" in both Unity and VS Code.
I tried changing 'local:' to 'Plundersea:' to no avail and now I have run out of ideas. Checking the samples also does not help identifying what I am doing wrong.
Could someone point me in the right direction please?
I am experimenting with NoesisGUI in C# with Unity, just following the first step guide right now and I have hit a snag with trying to show a secondary UserControl as described here:
https://www.noesisengine.com/docs/Gui.C ... aml-assets
So I have the auto-generated main view
XAML
Code: Select all
<UserControl x:Class="Plundersea.PlunderseaMainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Border Background="DodgerBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="50,20">
<StackPanel>
<TextBlock Text="Hello World" FontSize="30" Foreground="White"/>
<Button Content="Button" Margin="0,10,0,0"/>
<local:CrewInfo />
</StackPanel>
</Border>
</UserControl>
Code: Select all
#if UNITY_5_3_OR_NEWER
#define NOESIS
using Noesis;
#else
using System;
using System.Windows.Controls;
#endif
namespace Plundersea
{
/// <summary>
/// Interaction logic for PlunderseaMainView.xaml
/// </summary>
public partial class PlunderseaMainView : UserControl
{
public PlunderseaMainView()
{
InitializeComponent();
}
#if NOESIS
private void InitializeComponent()
{
NoesisUnity.LoadComponent(this);
}
#endif
}
}
XAML
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Plundersea.CrewInfo"
x:Name="CrewInfo"
>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="Click me" Click="Button_Click"/>
<TextBlock Text="{Binding Counter, ElementName=Root, StringFormat='Button clicked {0} time(s)'}" Margin="5,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
</UserControl>
Code: Select all
#if UNITY_5_3_OR_NEWER
#define NOESIS
using Noesis;
#else
using System.Windows;
using System.Windows.Controls;
#endif
namespace Plundersea
{
public partial class CrewInfo: Noesis.UserControl
{
public CrewInfo()
{
InitializeComponent();
}
public int Counter
{
get { return (int)GetValue(CounterProperty); }
set { SetValue(CounterProperty, value); }
}
public static readonly DependencyProperty CounterProperty = DependencyProperty.Register(
"Counter", typeof(int), typeof(CrewInfo), new PropertyMetadata(0));
#if NOESIS
protected override bool ConnectEvent(object source, string eventName, string handlerName)
{
if (eventName == "Click" && handlerName == "Button_Click")
{
((Button)source).Click += this.Button_Click;
return true;
}
return false;
}
private void InitializeComponent()
{
NoesisUnity.LoadComponent(this);
}
#endif
private void Button_Click(object sender, RoutedEventArgs args)
{
Counter++;
}
};
}
- I changed the namespace for 'CrewInfo' from 'Testing' to 'Plundersea'
- I added '<local:CrewInfo />' to PlunderseaMainView.xaml
Now it seems CrewInfo is not able to be found because I get an error "Namespace prefix not declared" in both Unity and VS Code.
I tried changing 'local:' to 'Plundersea:' to no avail and now I have run out of ideas. Checking the samples also does not help identifying what I am doing wrong.
Could someone point me in the right direction please?
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Namespace prefix not declared
Hello,
You just need to add the namespace definition for using the corresponding prefix:
You just need to add the namespace definition for using the corresponding prefix:
Code: Select all
<UserControl x:Class="Plundersea.PlunderseaMainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Plundersea">
...
<local:CrewInfo />
...
</UserControl>Re: Namespace prefix not declared
That was the missing key.
Thank you very much! :)
Thank you very much! :)
Who is online
Users browsing this forum: Google [Bot] and 5 guests