Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TextBox instead of TextBlock for displaying read only property #1540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Windows;
using System.Windows.Controls;
using Xceed.Wpf.Toolkit.PropertyGrid.Editors;

namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors
{
public class ReadOnlyTextBoxEditor : TypeEditor<TextBox>
{
protected override TextBox CreateEditor()
{
return new PropertyGridReadOnlyTextBoxEditor();
}

protected override void SetValueDependencyProperty()
{
ValueProperty = TextBox.TextProperty;
}

}

public class PropertyGridReadOnlyTextBoxEditor : TextBox
{
static PropertyGridReadOnlyTextBoxEditor()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyGridReadOnlyTextBoxEditor), new FrameworkPropertyMetadata(typeof(PropertyGridReadOnlyTextBoxEditor)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ This program is provided to you under the terms of the Microsoft Public

using System.Windows.Controls;
using System.Windows;
using System;

namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors
{
[Obsolete("Use ReadOnlyTextBoxEditor instead which uses a TextBox control for displaying content since TextBlock doesn't support ControlTemplate for customization")]
public class TextBlockEditor : TypeEditor<TextBlock>
{
protected override TextBlock CreateEditor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ internal FrameworkElement GenerateChildrenEditorElement( PropertyItem propertyIt
if( editorElement == null )
{
if( pd.IsReadOnly )
editor = new TextBlockEditor();
editor = new ReadOnlyTextBoxEditor();

// Fallback: Use a default type editor.
if( editor == null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal static ITypeEditor CreateDefaultEditor( Type propertyType, TypeConverte
// Otherwise, return a TextBlock editor since no valid editor exists.
editor = (typeConverter != null && typeConverter.CanConvertFrom( typeof( string ) ))
? (ITypeEditor)new TextBoxEditor()
: (ITypeEditor)new TextBlockEditor();
: (ITypeEditor)new ReadOnlyTextBoxEditor();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,19 @@
Value="Gray" />
</Style>

<!-- PropertyGrid MaskedTextBox Editors -->
<!-- PropertyGrid ReadOnly TextBox Editor -->
<Style TargetType="{x:Type editor:PropertyGridReadOnlyTextBoxEditor}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Foreground" Value="Gray" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock TextTrimming="CharacterEllipsis" Margin="5,0,0,0" Text="{Binding Path=Value}"></TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- PropertyGrid MaskedTextBox Editors -->
<Style TargetType="{x:Type editor:PropertyGridEditorMaskedTextBox}"
BasedOn="{StaticResource {x:Type TextBox}}">
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,20 @@
Value="Gray" />
</Style>

<!-- PropertyGrid MaskedTextBox Editors -->
<!-- PropertyGrid ReadOnly TextBox Editor -->
<Style TargetType="{x:Type editor:PropertyGridReadOnlyTextBoxEditor}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Foreground" Value="Gray" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock TextTrimming="CharacterEllipsis" Margin="5,0,0,0" Text="{Binding Path=Value}"></TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>


<!-- PropertyGrid MaskedTextBox Editors -->
<Style TargetType="{x:Type editor:PropertyGridEditorMaskedTextBox}"
BasedOn="{StaticResource {x:Type TextBox}}">
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
<Compile Include="PropertyGrid\Implementation\Converters\IsDefaultCategoryConverter.cs" />
<Compile Include="PropertyGrid\Implementation\Converters\IsStringEmptyConverter.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\CollectionEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ReadOnlyTextBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\SourceComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\TrimmedTextBlock.cs" />
<Compile Include="Core\Converters\WindowContentBorderMarginConverter.cs" />
Expand Down