I want to create styled editor for my current page. I use it few times so i decide to wrote style for this element and wondering how to use Behaviors inside style. If i do this like regular way, everything is working fine
<Editor Style="{StaticResource TestEditor}"/>
<Editor.Behaviors>
<toolkit:EventToCommandBehavior
EventName="Unfocused"
Command="{Binding Source={x:Reference TestEditorPage}, Path=BindingContext.UnfocusedCommand}"
CommandParameter="{Binding .}">
</toolkit:EventToCommandBehavior>
</Editor.Behaviors>
</Editor>
So how to do the same but in my style if it is possible:
<Style x:Key="TestEditor"
TargetType="Editor">
<Setter Property="AutoSize" Value="TextChanges"/>
<Setter Property="Grid.Column" Value="1"/>
<Setter Property="Placeholder" Value="Enter question answer"/>
<Setter Property="Text" Value="{Binding Source={RelativeSource AncestorType={x:Type models:TestAnswerResponce}}, Path=Answer}"/>
<Setter Property="Behaviors">
<!-- Behavior -->
</Setter>
</Style>
As a workaround, you could set the value of attach property to EventToCommandBehavior. Try the following code:
First, create a behaviour class in which adds an attached property.
And in xaml, consume the behaviour.
This is my xaml:
In code behind .cs file, don't forget to set the bindingContext for the page.
In ViewModel, I define the UnfocusedCommand and MyEditorText property. And each time editor lose focus (tap the entry below it), the command will fire.
Hope it works.