question

JassimAlRahma-9056 avatar image
0 Votes"
JassimAlRahma-9056 asked AdnanDedic edited

FontImageSource's Trigger

Hi,

How can I have a Trigger for FontImageSource? In below code for example, I want to sent the FontImageSource's Color to White when the value of Binding's post_liked is = 1


 <Image Grid.Column="0" WidthRequest="50" ClassId="LK" HorizontalOptions="Start" VerticalOptions="Center">
 <Image.Source>
     <FontImageSource FontFamily="FontRegular" Glyph="{StaticResource IconLike}" Color="LightGray" />
 </Image.Source>
 <Image.Triggers>
     <DataTrigger TargetType="Image" Binding="{Binding post_liked}" Value="1">
         <Setter Property="FontImageSource Color" Value="White" />
     </DataTrigger>
 </Image.Triggers>
 <Image.GestureRecognizers>
     <TapGestureRecognizer Tapped="LikePostTapGestureRecognizer_Tapped" />
 </Image.GestureRecognizers>
 </Image>



Kindly help..

Thanks,
Jassim

dotnet-csharpdotnet-xamarindotnet-standard
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AdnanDedic avatar image
0 Votes"
AdnanDedic answered JassimAlRahma-9056 commented

Hi,

If you want to do it using data trigger then you should set "FontImageSource" name, set target name in the setter, and fix target property name.

 <Image Grid.Column="0" WidthRequest="50" ClassId="LK" HorizontalOptions="Start" VerticalOptions="Center">
  <Image.Source>
      <FontImageSource x:Name="LikeIconImageSource" FontFamily="FontRegular" Glyph="{StaticResource IconLike}" Color="LightGray" />
  </Image.Source>
  <Image.Triggers>
      <DataTrigger TargetType="Image" Binding="{Binding post_liked}" Value="1">
          <Setter TargetName="LikeIconImageSource" Property="Color" Value="White" />
      </DataTrigger>
  </Image.Triggers>
  <Image.GestureRecognizers>
      <TapGestureRecognizer Tapped="LikePostTapGestureRecognizer_Tapped" />
  </Image.GestureRecognizers>
  </Image>

There are also other approaches like value converters, etc.

BR,
Adnan

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am getting:

Error XFC0001: Cannot resolve property "Color" on type "Image (property missing or missing accessors)". (XFC0001)

0 Votes 0 ·
AdnanDedic avatar image
0 Votes"
AdnanDedic answered AdnanDedic edited

Hi,
Sorry, the correct property name is "FontImageSource.Color". Here is the updated and tested solution:

     <Image Grid.Column="0" WidthRequest="50" ClassId="LK" HorizontalOptions="Start" VerticalOptions="Center">
         <Image.Source>
             <FontImageSource x:Name="LikeImageSource" FontFamily="FontRegular"  Glyph="☻" Color="LightGray" />
         </Image.Source>
         <Image.Triggers>
             <DataTrigger TargetType="Image" Binding="{Binding post_liked}" Value="1">
                 <Setter TargetName="LikeImageSource" Property="FontImageSource.Color" Value="Red" />
             </DataTrigger>
         </Image.Triggers>
     </Image>

121471-capture.jpg

BR,
Adnan



capture.jpg (422.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.