avalonia add tag
On a `VM` part I have the `SomeItem` type:

type SomeItem = {
    Index : int
    IsCurrent : bool

and the `SomeItems:SomeItem[]` property.

On a `View` part I have a`ListBox` where I bind the `Items` and the `SelectedIndex` properties:

    Items="{Binding SomeItems}"
    SelectedIndex="{Binding CurrentIndex}">
            <WrapPanel />
            <Border BorderBrush="{Binding IsCurrent, Converter={StaticResource b2bConv}}}" 
                <Grid />

(parts that unrelated to the Q were omitted)

Here, I use the `BoolToBrushConverter` converter to determine the color of a border depending on the `IsCurrent` property.

type BoolToBrushConverter() = 
    interface IValueConverter with
        member this.Convert(value: obj, _, _, _): obj = 
            match value with
            | :? bool as b ->
                if b then Brushes.Green else Brushes.LightGray
            | _ -> Brushes.Black
            |> box

        member this.ConvertBack(_, _, _, _): obj = 
            raise (System.NotImplementedException())

But now I want to get rid of this `IsCurrent` property since it's not very useful on a VM layer. For `WPF` I'd probably use `DataTrigger` but this feature is unsupported in Avalonia yet.

So how can I achieve the same look ?

Version of Avalonia: `0.9.11`
Top Answer
Instead of changing the border you can change the background of a `ListBoxItem` - the result would be the same.

To apply changes use next styles:

    <Style Selector="ListBoxItem:selected /template/ ContentPresenter">
        <Setter Property="Background" Value="Green" />
    <Style Selector="ListBoxItem">
        <Setter Property="Background" Value="LightGray" />

First one uses the `selected` pseudoclass (you can read more about that in the [docs](https://avaloniaui.net/docs/styles/styles#pseudoclasses)). 

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.