Back to Devexpress

BarItem.Triggers Property

wpf-devexpress-dot-xpf-dot-bars-dot-baritem-98730289.md

latest6.2 KB
Original Source

BarItem.Triggers Property

Gets or sets a collection of ItemTriggerBase objects that apply property values based on specified conditions.

Namespace : DevExpress.Xpf.Bars

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public BarItemTriggerCollection Triggers { get; set; }
vb
Public Property Triggers As BarItemTriggerCollection

Property Value

TypeDescription
BarItemTriggerCollection

A collection of ItemTriggerBase objects. The default is an empty collection.

|

Remarks

Use the BarItem.Triggers property to customize a BarItem‘s appearance properties based on a condition. When you apply the standard WPF styles and triggers to the BarItem , triggers do not customize the appearance of bound BarItemLinks‘ independently. The BarItem.Triggers property checks the trigger condition for each BarItemLink that is bound to the BarItem.

Tip

For more information on the bar item structure, refer to the following help topic: Items and Links.

BarItem.Triggers support ItemTrigger and ItemMultiTrigger. The ItemTrigger and ItemMultiTrigger API is based on the standard WPF triggers with the following exceptions:

ItemTrigger

The ItemTrigger class encapsulates the Trigger and DataTrigger functionality.

The following code sample sets the BarCheckItem‘s Content property to On when the BarCheckItem is checked:

xaml
<dxb:BarCheckItem Content="Off">
    <dxb:BarCheckItem.Triggers>
        <dxb:ItemTrigger Property="IsChecked" Value="True">
            <dxb:ItemSetter Property="Content" Value="On"/>
        </dxb:ItemTrigger>
    </dxb:BarCheckItem.Triggers>
</dxb:BarCheckItem>

ItemMultiTrigger

The ItemMultiTrigger class encapsulates the MultiTrigger and MultiDataTrigger functionality.

The ItemMultiTrigger allows you to set property values based on a condition collection. A condition is met when the ItemTriggerCondition.Value is equal to the ItemTriggerCondition.Property value or data returned by the ItemTriggerCondition.Binding.

The following code sample sets the BarButtonItem‘s Foreground to Red when the BarButtonItem is located in the MainMenu and the view model’s HighlightItemsInMenu property is true:

xaml
<dxb:BarButtonItem Content="Item">
    <dxb:BarButtonItem.Triggers>
        <dxb:ItemMultiTrigger>
            <dxb:ItemMultiTrigger.Conditions>
                <dxb:ItemTriggerCondition Property="ContainerType" Value="MainMenu"/>
                <dxb:ItemTriggerCondition Binding="{Binding HighlightItemsInMenu}" Value="True"/>
            </dxb:ItemMultiTrigger.Conditions>
            <dxb:ItemSetter Property="Foreground" Value="Red"/>
        </dxb:ItemMultiTrigger>
    </dxb:BarButtonItem.Triggers>
</dxb:BarButtonItem>
csharp
using DevExpress.Mvvm;

public class ViewProperties : BindableBase {
    public bool HighlightItemsInMenu {
        get { return GetValue<bool>(); }
        set { SetValue(value); }
    }
}
vb
Imports DevExpress.Mvvm

Public Class ViewProperties
    Inherits BindableBase

    Public Property HighlightItemsInMenu As Boolean
        Get
            Return GetValue(Of Boolean)()
        End Get
        Set(ByVal value As Boolean)
            SetValue(value)
        End Set
    End Property
End Class
csharp
public partial class MainWindow : DevExpress.Xpf.Core.ThemedWindow
    {
        public MainWindow()
        {
            DataContext = new ViewProperties() { HighlightItemsInMenu = true };
            InitializeComponent();
        }
    }
vb
Public Partial Class MainWindow
    Inherits DevExpress.Xpf.Core.ThemedWindow

    Public Sub New()
        DataContext = New ViewProperties() With {
            .HighlightItemsInMenu = True
        }
        InitializeComponent()
    End Sub
End Class

See Also

BarItem Class

BarItem Members

DevExpress.Xpf.Bars Namespace