Change style of a TreeListView

Grids for WPF Forum

Posted 1 year ago by Jolanthe Wolfsdörfer
Version: 22.1.0
Avatar

I would like to change the style of a TreeListView.

In our TreeListView I have activated the multi selection (SelectionMode = Extended). Now I want to indicate which ListItem has the KeyboardFocus with a border.

Therefore I use a trigger within the <TreeListView.ItemContainerStyle>.

If no predefined style of the TreeListView is visible (e.g. MouseHover or SelectedItem), the border of my trigger is visible.
But when I e.g. hover over the affected ListItem, my style (border) disappears and only the predefined style of the TreeListView is visible.

Also the definition of a multi trigger does not work.


Here is my code to set the style via trigger:

<grids:TreeListView.ItemContainerStyle>
  <Style TargetType="{x:Type grids:TreeListViewItem}">
    <Style.Triggers>
      <Trigger Property="IsKeyboardFocused" Value="True">
        <Setter Property="BorderBrush" Value="Black"/>
      </Trigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsMouseOver" Value="True"/>
          <Condition Property="IsKeyboardFocused" Value="True"/>
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter Property="Background" Value="{DynamicResource {x:Static themes:AssetResourceKeys.ListItemBackgroundHoverBrushKey}}"/>
          <Setter Property="BorderBrush" Value="Black"/>
        </MultiTrigger.Setters>
      </MultiTrigger>
    </Style.Triggers>
  </Style>
</grids:TreeListView.ItemContainerStyle>


Shouldn't the definition via trigger work as expected? If not, how can I visualize the tree item with the keyboard focus?

Comments (1)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The problem here is there are triggers in the TreeListViewItem's default template that affect the chrome within when states (hover, etc.) are active, and those setters will override anything set on the control's Background/BorderBrush properties that your Triggers are affecting.  You would need to download our default styles/templates (you can do this from your account's Purchases and Licenses list since you have WPF Studio), and then go to the Grids Themes and look in there for TreeListViewItemContainerStyle.  Clone the Style, update it per your needs,  and assign it to the TreeListView.ItemContainerStyle property.  That should allow you to customize it properly via the triggers in the template.

I will note that when the control gains keyboard focus through tabbing, it should be showing the dashed focus line on the focused item by default, even when in multi-selection mode.  But that dashed focus line doesn't show when clicking items, per WPF input standards.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.