AvaloniaUI / Avalonia.Xaml.Behaviors

Port of Windows UWP Xaml Behaviors for Avalonia Xaml.
MIT License
396 stars 48 forks source link

DataTriggerBehavior not change property on ListBoxItem #78

Closed Tenjim closed 8 months ago

Tenjim commented 3 years ago

Hi there,

I have an issue when I'm using a DataTriggerBehavior on ListboxItem. I want just to set background (after that, my final purpose is to set template and contentTemplate) on listboxItem with ChangePropertyAction like this :

 <ListBox
          Items="{Binding Persons}"
          SelectionMode="Multiple"
          x:Name="ListPerson">

<Interaction.Behaviors>
          <DataTriggerBehavior Binding="{Binding SelectedPerson}" Value="{x:Static enums:PersonType.SuperUser}">

            <ChangePropertyAction TargetObject="{Binding #ListPerson.Items}" PropertyName="Background"
                                  Value="Red" />
          </DataTriggerBehavior>
</ListBox>

Did I missing something on the DataTriggerBehavior current behavior because the property won't change after DataTrigger ? I have checked if the binding have the right value and it's that case.

After check, it's maybe related to this issue ? Can't use static object binding with DataTriggerBehavior Thank in advance.

maxkatz6 commented 3 years ago

What if you will use binding to the listbox directly? Like "{Binding #ListPerson.SelectfedItem}". Also in your example you actually missed SelectfedItem to SelectedPerson binding in the ListBox itself. At least this would be a problem.

Tenjim commented 3 years ago

Hi @maxkatz6 As basis, I wanted to change template on all ListBoxItem so I wanted to target ListPerson.Items.

Btw the workaround was your answer about this discussions about several classes styles with Avalonia :

here