Back to Devexpress

TextEditBase.EditNonEditableTemplate Property

wpf-devexpress-dot-xpf-dot-editors-dot-texteditbase-88bbc066.md

latest8.9 KB
Original Source

TextEditBase.EditNonEditableTemplate Property

Gets or sets a template that defines the editor’s presentation when the editor’s text field is not editable. This is a dependency property.

Namespace : DevExpress.Xpf.Editors

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

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
[Browsable(false)]
public ControlTemplate EditNonEditableTemplate { get; set; }
vb
<Browsable(False)>
Public Property EditNonEditableTemplate As ControlTemplate

Property Value

TypeDescription
ControlTemplate

A ControlTemplate object representing the editor’s template.

|

Remarks

The EditNonEditableTemplate property is in effect for the ButtonEdit editor and its derived editors (such as the ComboBoxEdit).

The template, specified via the EditNonEditableTemplate property, is applied to the editor’s text field when the ButtonEdit.IsTextEditable property is set to false. In this case, the editor’s text field cannot be edited, and an end user can change the editor’s value only by choosing a new value in editor’s popup.

The EditNonEditableTemplate property is not used when the editor is in in-place inactive mode (e.g., when an editor is used in a GridControl cell and this cell is not activated).

EditNonEditableTemplate ‘s *DataContext depends on whether the editor is standalone or in-place. In both cases, use the BaseEdit.OwnerEdit attached property to bind to editor properties, for example:

xaml
<dxe:ComboBoxEdit.EditNonEditableTemplate>
    <ControlTemplate>
        <TextBlock Text="{Binding (dxe:BaseEdit.OwnerEdit).EditValue}"/>
    </ControlTemplate>
</dxe:ComboBoxEdit.EditNonEditableTemplate>

Refer to the Assign Editors to Cells topic for more information.

Example

The following example shows how to customize the in-place combo box editor’s appearance when its text field is not editable. In this example, in-place combo boxes are used to edit the ‘Access Card Color’ column field values. The appearance of the editors’ items on the drop-down list is specified via the ItemTemplate property. As for the edit box, you can either apply the same template by setting the ApplyItemTemplateToSelectedItem property to true or specify another template using the EditNonEditableTemplate property (in this example, we used the second approach).

xaml
<Window x:Class="TextEdit_EditNonEditableTemplate.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="Access Cards"
        Width="300"
        Height="200">

    <dxg:GridControl Name="gridControl1">
        <dxg:GridControl.Columns>
            <dxg:GridColumn FieldName="Name" />
            <dxg:GridColumn FieldName="CardColor" Header="Access Card Color">
                <dxg:GridColumn.EditSettings>
                    <dxe:ComboBoxEditSettings IsTextEditable="False">
                        <dxe:ComboBoxEditSettings.ItemTemplate>
                            <DataTemplate>
                                <Border Background="Transparent">
                                    <StackPanel Orientation="Horizontal">
                                        <Rectangle Width="10"
                                                   Height="10"
                                                   Margin="6,0,6,0"
                                                   Fill="{Binding TargetNullValue=Transparent}"
                                                   RadiusX="2"
                                                   RadiusY="2" />
                                        <TextBlock Text="{Binding}" />
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </dxe:ComboBoxEditSettings.ItemTemplate>
                        <dxe:ComboBoxEditSettings.EditNonEditableTemplate>
                            <ControlTemplate>
                                <Rectangle Margin="2"
                                           Fill="{Binding EditValue, RelativeSource={RelativeSource TemplatedParent}}"
                                           RadiusX="2"
                                           RadiusY="2" />
                            </ControlTemplate>
                        </dxe:ComboBoxEditSettings.EditNonEditableTemplate>
                        <dxe:ComboBoxEditSettings.Items>
                            <sys:String>Red</sys:String>
                            <sys:String>Green</sys:String>
                            <sys:String>Blue</sys:String>
                        </dxe:ComboBoxEditSettings.Items>
                    </dxe:ComboBoxEditSettings>
                </dxg:GridColumn.EditSettings>
            </dxg:GridColumn>
        </dxg:GridControl.Columns>
        <dxg:GridControl.View>
            <dxg:TableView AutoWidth="True" />
        </dxg:GridControl.View>
    </dxg:GridControl>

</Window>
csharp
using System.Collections.Generic;
using System.Windows;

namespace TextEdit_EditNonEditableTemplate {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            List<Employee> data = new List<Employee>();
            data.Add(new Employee { Name = "Steven", CardColor = "Red" });
            data.Add(new Employee { Name = "Mary", CardColor = "Green" });
            data.Add(new Employee { Name = "John", CardColor = "Blue" });
            data.Add(new Employee { Name = "Claudia", CardColor = "Red" });
            gridControl1.ItemsSource = data;
        }
    }
    public class Employee {
        public string Name { get; set; }
        public string CardColor { get; set; }
    }
}
xaml
<Application x:Class="TextEdit_EditNonEditableTemplate.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.Collections.Generic
Imports System.Windows

Namespace TextEdit_EditNonEditableTemplate
    Partial Public Class Window1
        Inherits Window

        Public Sub New()
            InitializeComponent()
            Dim data As New List(Of Employee)()
            data.Add(New Employee With { _
                .Name = "Steven", _
                .CardColor = "Red" _
            })
            data.Add(New Employee With { _
                .Name = "Mary", _
                .CardColor = "Green" _
            })
            data.Add(New Employee With { _
                .Name = "John", _
                .CardColor = "Blue" _
            })
            data.Add(New Employee With { _
                .Name = "Claudia", _
                .CardColor = "Red" _
            })
            gridControl1.ItemsSource = data
        End Sub
    End Class
    Public Class Employee
        Public Property Name() As String
        Public Property CardColor() As String
    End Class
End Namespace

See Also

EditTemplate

Assign Editors to Cells

TextEditBase Class

TextEditBase Members

DevExpress.Xpf.Editors Namespace