Reputation: 332
Can I use a Behavior to get another View? let me explain
public class EditorBehavior : Behavior<Editor>
{
public Editor EditorMessage { get; set; }
}
<Entry >
<Entry.Behavior>
<local:EditorBehavior EditorMessage=""/>
</Entry.Behavior>
</Entry>
<Editor x:Name="EditorMessage"/>
How to use the Editor in other view behavior?
Upvotes: 0
Views: 55
Reputation: 16547
That is fairly easy you will have to get it using a BindableProperty
:
public static readonly BindableProperty BindedViewProperty = BindableProperty.Create(
nameof(BindedView),
typeof(Xamarin.Forms.View),
typeof(EditorBehavior));
public Xamarin.Forms.View BindedView
{
get => (Xamarin.Forms.View)GetValue(BindedViewProperty);
set => SetValue(BindedViewProperty, value);
}
Once you do that you can just pass your View using BindableProperty
or x:Name
<local:EditorBehavior BindedView="{x:Reference EditorMessage}"/>
But make sure you understand the Behavior lifecycle before using this, Also it would make more sense if you do not share the View itself but the concerned property so you actually do not make changes in the view from somewhere else.
Upvotes: 1