Avalonia.Xaml.Behaviors icon indicating copy to clipboard operation
Avalonia.Xaml.Behaviors copied to clipboard

DataTriggerBehavior not change property on ListBoxItem

Open Tenjim opened this issue 2 years ago • 2 comments

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.

Tenjim avatar Oct 07 '21 09:10 Tenjim

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.

maxkatz6 avatar Oct 28 '21 22:10 maxkatz6

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

Tenjim avatar Oct 29 '21 07:10 Tenjim