EditableContentControl EditableContent property

Editors for WPF Forum

Posted 6 months ago by Ethem Acar
Version: 23.1.4

In the docs it says:

When entering edit mode, the Content property value is copied to the EditableContent property, and the UI switches to a TextBox for editing the editable content. Note that an alternate template could be provided for the control to support an editor other than a TextBox.

Is there an example of this? Trying to figure out how I can use colorpicker instead of textbox.

Comments (1)

Answer - Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA


The default Template for the control is a good example:

<ControlTemplate TargetType="controls:EditableContentControl">
	<Grid Background="{TemplateBinding Background}">
		<ContentPresenter x:Name="presenter" Margin="2,0" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" 
							ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}">
				<Style TargetType="TextBlock">
					<Setter Property="TextTrimming" Value="CharacterEllipsis" />
					<Setter Property="TextWrapping" Value="NoWrap" />
					<Setter Property="VerticalAlignment" Value="Center" />
		<TextBox x:Name="textBox" MinWidth="30" MinHeight="0" Padding="0" BorderThickness="0" FontSize="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FontSize}" 
					Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=EditableContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
					TextWrapping="NoWrap" HorizontalAlignment="Left" VerticalAlignment="Center" Visibility="Collapsed" />
		<Trigger Property="IsEditing" Value="True">
			<Setter TargetName="presenter" Property="Visibility" Value="Collapsed" />
			<Setter TargetName="textBox" Property="Visibility" Value="Visible" />

You can see there how the TextBox is swapped in when IsEditing=true.  In a cloned ControlTemplate, you could replace the TextBox with some other control if you wish.

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.