Back to Devexpress

LookUpEditBase.ApplyItemTemplateToSelectedItem Property

wpf-devexpress-dot-xpf-dot-editors-dot-lookupeditbase-f4c2701b.md

latest8.1 KB
Original Source

LookUpEditBase.ApplyItemTemplateToSelectedItem Property

Gets or sets whether to apply the ItemTemplate to the selected item, displayed within the edit box. This is a dependency property.

Namespace : DevExpress.Xpf.Editors

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

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public bool ApplyItemTemplateToSelectedItem { get; set; }
vb
Public Property ApplyItemTemplateToSelectedItem As Boolean

Property Value

TypeDescription
Boolean

true to apply the item template to the selected item; otherwise, false.

|

Remarks

There are two properties that allow you to change the visual presentation of the selected item (displayed within the edit box) and items displayed within the dropdown list. These are the BaseEdit.EditTemplate and LookUpEditBase.ItemTemplate properties, respectively. In some instances (e.g., creating an image combobox), it is required to use one template to present the selected item and items displayed within the dropdown list. To do this, set the ApplyItemTemplateToSelectedItem property to true.

The item template is applied only if the combobox’s ButtonEdit.IsTextEditable property is set to false.

Note

Using the ApplyItemTemplateToSelectedItem property overrides the editor’s default template and disables the BaseEdit.NullText property (if specified). To specify the text displayed within the edit box when the editor’s value is null , use the TextEditBase.EditNonEditableTemplate property:

xaml
<dxe:ComboBoxEdit.EditNonEditableTemplate>
                <ControlTemplate>
                    <Grid>
                        <Grid.Resources>
                            <dx:NullableToVisibilityConverter x:Key="c1"/>
                            <dx:NullableToVisibilityConverter x:Key="c" Invert="True"/>
                        </Grid.Resources>
                        <TextBlock Text="Select a Color" Visibility="{Binding EditValue, Converter={StaticResource c}}"/>
                        <StackPanel Orientation="Horizontal" Margin="3" Visibility="{Binding EditValue, Converter={StaticResource c1}}">
                            <Rectangle Width="16" Height="16" Margin="3" Fill="{Binding EditValue}" />
                            <TextBlock Text="{Binding EditValue.Color}" Margin="3" />
                        </StackPanel>
                    </Grid>
                </ControlTemplate>
            </dxe:ComboBoxEdit.EditNonEditableTemplate>

Example

The following example shows how to create an image combobox via templates.

xaml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="ComboBoxEdit_CreatingImageComboBox.Window1"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="Creating an Image ComboBox"
        Height="300" Width="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="100" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="22" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <dxe:ComboBoxEdit ApplyItemTemplateToSelectedItem="True" IsTextEditable="False"
                          Text="(None)" Grid.Row="1" Grid.Column="1" Padding="5,2,5,2">
            <dxe:ComboBoxEdit.ItemTemplate>
                <DataTemplate>
                    <Border Background="Transparent">
                        <StackPanel Orientation="Horizontal">
                            <Rectangle Width="10" Height="10" Fill="{Binding}"
                                       RadiusX="2" RadiusY="2"
                                       Margin="6,0,6,0" />
                            <TextBlock Text="{Binding}" />
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </dxe:ComboBoxEdit.ItemTemplate>
            <sys:String>Red</sys:String>
            <sys:String>Green</sys:String>
            <sys:String>Blue</sys:String>
        </dxe:ComboBoxEdit>
    </Grid>
</Window>
xaml
<Application x:Class="ComboBoxEdit_CreatingImageComboBox.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>
vb
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Windows

Namespace ComboBoxEdit_CreatingImageComboBox
    ''' <summary>
    ''' Interaction logic for App.xaml
    ''' </summary>
    Partial Public Class App
        Inherits Application

    End Class
End Namespace
vb
Imports System.Windows

Namespace ComboBoxEdit_CreatingImageComboBox
    ''' <summary>
    ''' Interaction logic for Window1.xaml
    ''' </summary>
    Partial Public Class Window1
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub
    End Class
End Namespace
csharp
using System.Windows;

namespace ComboBoxEdit_CreatingImageComboBox {
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
        }
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the ApplyItemTemplateToSelectedItem property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-apply-data-annotations/CS/Apply Data Annotations/MainWindow.xaml#L13

xml
IsTextEditable="False"
                      ApplyItemTemplateToSelectedItem="True"/>
</DataTemplate>

wpf-synchronous-theme-preload-with-splashscreen/CS/ThemePreloadwithSplashscreen/ComplexWindow.xaml#L65

xml
MinWidth="75"
ApplyItemTemplateToSelectedItem="True"
EditValue="{Binding Path=Prefix, Mode=TwoWay}"

See Also

ItemTemplate

EditTemplate

LookUpEditBase Class

LookUpEditBase Members

DevExpress.Xpf.Editors Namespace