realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

in Xaml, Behaviors are searched for in the namespace NoesisApp, but registered in an anonymous namespace

15 May 2019, 12:05

class MouseWheelBehavior final: public NoesisApp::BehaviorT<Noesis::FrameworkElement>
{
public:
    MouseWheelBehavior() = default;
    ~MouseWheelBehavior() = default;

protected:
    Noesis::Ptr<Noesis::Freezable> CreateInstanceCore() const override;
  
    void OnAttached() override;
    void OnDetaching() override;

private:
	void OnPreviewMouseWheel(BaseComponent* sender, const MouseWheelEventArgs& e);

private:
    NS_DECLARE_REFLECTION(MouseWheelBehavior, NoesisApp::BehaviorT<Noesis::FrameworkElement>)
};

NS_IMPLEMENT_REFLECTION(MouseWheelBehavior)
{
	NsMeta<TypeId>("MouseWheelBehavior");
}
		
XAML
      <DataTemplate x:Key="Template.MaterialGroup" DataType="{x:Type MaterialGroupComponent}">
        <Grid>
          <Rectangle Fill="{StaticResource MainAccentBrush}" Height="2" VerticalAlignment="Top" Margin="-4,-4,-4,0"></Rectangle>

          <TreeView  x:Name="tvNodes" ItemsSource="{Binding Childs, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Top"
                 ItemContainerStyle="{StaticResource MaterialTreeViewItemsStyle}" SnapsToDevicePixels="True"
                 Background="{StaticResource panelBgBrush}"
                 BorderThickness="0" BorderBrush="{StaticResource MainAccentBrush}" Margin="0,20,0,0"
                 ScrollViewer.VerticalScrollBarVisibility="Auto"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                 
                  <i:Interaction.Behaviors>
                      <ei:MouseWheelBehavior/>
                  </i:Interaction.Behaviors>            
          </TreeView>
        </Grid>
      </DataTemplate>
Log: Controls/Material.xaml(169): Unknown type 'NoesisApp.MouseWheelBehavior'..
 
mingingmingler
Posts: 23
Joined: 15 Jan 2018, 00:03

Re: in Xaml, Behaviors are searched for in the namespace NoesisApp, but registered in an anonymous namespace

15 May 2019, 16:16

It's looking for the reflection type id, not the class namespace.

Change
NsMeta<TypeId>("MouseWheelBehavior");
to
NsMeta<TypeId>("NoesisApp.MouseWheelBehavior");
 
User avatar
sfernandez
Site Admin
Posts: 1933
Joined: 22 Dec 2011, 19:20

Re: in Xaml, Behaviors are searched for in the namespace NoesisApp, but registered in an anonymous namespace

15 May 2019, 16:41

In the xaml you have the following:
<ei:MouseWheelBehavior/>
That prefix is usually defined as:
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
Our XAML parser maps that namespace to "NoesisApp" because we have all default interactivity classes defined in there.

You can have your own behaviors and actions defined in your own namespaces, for example:
namespace RealEsMedia
{
  class MouseWheelBehavior final: public NoesisApp::BehaviorT<Noesis::FrameworkElement> { ... };
  
  NS_IMPLEMENT_REFLECTION(MouseWheelBehavior)
  {
    // This is the Namespace.ClassName used by the XAML parser
    NsMeta<TypeId>("RealEsMedia.MouseWheelBehavior");
  }
}
Then you just need to specify that namespace in your XAML:
<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
  xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
  xmlns:rem="clr-namespace:RealEsMedia">
    ...
    <i:Interaction.Behaviors>
        <rem:MouseWheelBehavior/>
    </i:Interaction.Behaviors>
    ...
</UserControl>
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: in Xaml, Behaviors are searched for in the namespace NoesisApp, but registered in an anonymous namespace

15 May 2019, 17:07

ok, thank

I thought that for Behaviors it is necessary to use the ei namespace

Who is online

Users browsing this forum: No registered users and 5 guests