Page 1 of 1

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

Posted: 15 May 2019, 12:05
by realesmedia
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'..

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

Posted: 15 May 2019, 16:16
by mingingmingler
It's looking for the reflection type id, not the class namespace.

Change
NsMeta<TypeId>("MouseWheelBehavior");
to
NsMeta<TypeId>("NoesisApp.MouseWheelBehavior");

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

Posted: 15 May 2019, 16:41
by sfernandez
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>

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

Posted: 15 May 2019, 17:07
by realesmedia
ok, thank

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