This is a migrated thread and some comments may be shown as answers.

Xamarin RadEntry Change Border Color on Focus

1 Answer 489 Views
Entry
This is a migrated thread and some comments may be shown as answers.
Mak
Top achievements
Rank 1
Mak asked on 20 Mar 2021, 09:59 PM

Want to change RadEntry Border Color on focus without code behind file. To achieve this Focus event converted to Command and IsSelectedFocused Command is firing on focus. After this VisualElement is converted to RadEntry & BorderSyle.Color changed to Brown does not have any impact.

Secondly, RadEntry Trigger IsFocused also does not have any impact. Please advise, in this regards.

<input:RadEntry Style="{StaticResource ProductLabelStyle}"
                WatermarkText="Product Name">
    <input:RadEntry.Behaviors>
        <common:RadEventToCommandBehavior EventName="Focused"
                                          Command="{Binding IsSelectedFocused}"/>
    </input:RadEntry.Behaviors>
    <input:RadEntry.Triggers>
        <Trigger Property="common:FocusElementHelper.IsFocused"
                 Value="True"
                 TargetType="input:RadEntry">
            <Setter Property="input:RadEntry.BorderStyle"
                    Value="{StaticResource ProductEntryFocusBorderStyle}"/>
        </Trigger>
    </input:RadEntry.Triggers>
</input:RadEntry>

 

private IAsyncCommand<object> _isSelectedFocused;
 
public IAsyncCommand<object> IsSelectedFocused => _isSelectedFocused ??= new AsyncCommand<object>(onSelectedFocus, canSelectedFocus);
 
private Task onSelectedFocus(object arg)
{
    if(!(arg is FocusEventArgs focusEventArgs))
    {
        return Task.CompletedTask;
    }
 
    if(focusEventArgs.VisualElement is RadEntry radEntry)
    {
        radEntry.BorderStyle.BorderColor = Color.Brown;
    }
    return Task.CompletedTask;
}

 

1 Answer, 1 is accepted

Sort by
0
Mak
Top achievements
Rank 1
answered on 21 Mar 2021, 10:41 PM

Trigger Property input:RadEntry.IsFocused did the job done.

<input:RadEntry Style="{StaticResource ProductLabelStyle}"    WatermarkText="e.g. Large Shampoo" x:Name="RadEntry1">                          
                            <input:RadEntry.Triggers>
                                <Trigger Property="input:RadEntry.IsFocused" Value="True" TargetType="input:RadEntry">
                                    <Setter Property="input:RadEntry.BorderStyle" Value="{StaticResource ProductEntrySelctionBorderStyle}"/>
                                </Trigger>
                            </input:RadEntry.Triggers>
                        </input:RadEntry>

Tags
Entry
Asked by
Mak
Top achievements
Rank 1
Answers by
Mak
Top achievements
Rank 1
Share this question
or