maui icon indicating copy to clipboard operation
maui copied to clipboard

DataTrigger doesn't change Rectangle background color on iOS

Open MaxxDelusional opened this issue 4 months ago • 7 comments

Description

I have a Rectangle defined in XAML, and I want to adjust its color based on a Data Trigger. I started with something simple like this.

 <Rectangle Grid.Row="0" Grid.Column="0" BackgroundColor="#00FF00">
     <Rectangle.Triggers>
         <DataTrigger TargetType="Rectangle" Binding="{Binding Cancelled}" Value="True">
             <Setter Property="BackgroundColor" Value="#FF0000" />
         </DataTrigger>
     </Rectangle.Triggers>
</Rectangle>

This works on Android, but on iOS the color is always #00FF00.

Cancelled is a Nullable Boolean defined in my ViewModel. I have verified that the value is indeed set to true. I am able to use the Cancelled binding on other Views to control things like visibility. For example, this works as expected.

 <Label IsVisible="{Binding Cancelled}" Text="Canceled" />

The last iteration in my attempt to make this works looks like this.

<Rectangle Grid.Row="0" Column="0">
    <Rectangle.Style>
        <Style TargetType="Rectangle">
            <Style.Triggers>
                <DataTrigger TargetType="Rectangle" Binding="{Binding Cancelled}" Value="{x:Null}">
                    <Setter Property="BackgroundColor" Value="#0000FF" />
                </DataTrigger>
                <DataTrigger TargetType="Rectangle" Binding="{Binding Cancelled}" Value="False">
                    <Setter Property="BackgroundColor" Value="#00FF00" />
                </DataTrigger>
                <DataTrigger TargetType="Rectangle" Binding="{Binding Cancelled}" Value="True">
                    <Setter Property="BackgroundColor" Value="#FF0000" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Rectangle.Style>
    
</Rectangle>

But, the color is still always #00FF00 on iOS. This issue seems to only affect BackgroundColor. For example, this trigger works as expected.

<Rectangle.Triggers>
    <DataTrigger TargetType="Rectangle" Binding="{Binding Cancelled}" Value="True">
        <Setter Property="HeightRequest" Value="500" />
    </DataTrigger>
</Rectangle.Triggers>

Using Background instead of BackgroundColor still doesn't work.

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

9.0.0-rc.2.24503.2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

MaxxDelusional avatar Oct 18 '24 15:10 MaxxDelusional