Forum Xamarin Xamarin.Forms

Label style is removed after datatrigger sets labels text property

PatrickJelittoPatrickJelitto Member ✭✭✭
edited May 2019 in Xamarin.Forms

Hello Community :),

i witnessed a strage behaviour in my xamarin forms app.

My xaml looks like this:

<Grid ColumnSpacing="1" RowSpacing="2" Padding="10">
    <StackLayout Orientation="Horizontal" Grid.Row="0">
        <Label Style="{StaticResource leftLabel}" Text="Caption" />
                                                <Label Style="{StaticResource **rightLabel**}">
                                                        <DataTrigger TargetType="Label" Binding="{Binding MyModel.DateTimeProperty, 
                                Converter={StaticResource IsGreaterDateTimeConverter}}" Value="True">
                                                            <Setter Property="Text" Value="{Binding MyModel.DateTimeProperty, StringFormat='{0:dd.MM.yyyy}'}"/>

Thats my StaticResource for the "rightLabel":

<Style x:Key="rightLabel" TargetType="Label">
             <Setter Property="VerticalTextAlignment" Value="Center"></Setter>
               <Setter Property="HorizontalTextAlignment" Value="End"></Setter>
               <Setter Property="Margin" Value="0,0,10,0"></Setter>
               <Setter Property="HorizontalOptions" Value="FillAndExpand"></Setter>
               <Setter Property="TextColor" Value="#4b4b4b"></Setter>

Now the issue:

The DateTimeProperty implements INotifyPropertyChanged. After the labels text is updated by the datatrigger, the Style "HorizontalTextAlignment="End" isnt working anymore.

The ValueConverter checks if the DateTime is greater than a fix DateTime Value and returns the boolean result.

Does anyone has witnessed a similar behaviour or knows how to fix it?

Thank you very much, Patrick


  • ColeXColeX Member, Xamarin Team Xamurai

    Would you mind sharing us a basic sample for the reproduction?

Sign In or Register to comment.