Hello! I am having quite a bit of trouble trying to add a conditional strikethrough effect to a label. The following generates an error "Can't resolved Effects on Label". I am trying to add a strikethrough effect to a label if the operation type is a certain value - otherwise it should just default to MyStyle.
I'm stuck and I would appreciate any tips! Thanks!
<Label Style="{StaticResource MyStyle}" Text="{Binding Name}"> <Label.Triggers> <DataTrigger Binding="{Binding Name.Operation}" TargetType="Label" Value="2"> <Setter Property="Effects"> <Setter.Value> <effects:StrikethoughEffect /> </Setter.Value> </Setter> </DataTrigger> </Label.Triggers> </Label>
You can use TextDecorations property in the version of Xamarin.Forms(3.3.x).
There are to ways to consume the effect :
in xaml
<Entry Text="Effect attached to an Entry" ...> <Entry.Effects> <local:FocusEffect /> </Entry.Effects> ... </Entry>
public HomePageCS () { ... entry.Effects.Add (Effect.Resolve ($"MyCompany.{nameof(FocusEffect)}")); ... }
Answers
Maybe its better to bind TextDecorations property of Label to property of ViewModel? And when your operation is changing just call OnPropertyChanged for that property?
Thank you. However, I do not believe TextDecorations are in the version of Xamarin.Forms I am using (3.2.x).
You can use TextDecorations property in the version of Xamarin.Forms(3.3.x).
There are to ways to consume the effect :
in xaml
in c#
I've reproduced the code. There are no 'Effects' in Setter's Property.
You can change the code as follows :