Enable multiline editing of string values in propertygrids

This commit is contained in:
Brant Martin
2018-06-23 03:21:45 -04:00
parent 07bb0fc4cf
commit 8b08f2b747
2 changed files with 17 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ namespace Torch.Views
public bool Enabled = true;
public bool Visible = true;
public bool ReadOnly = false;
public Type EditorType = null;
public DisplayAttribute()
{ }

View File

@@ -145,6 +145,11 @@ namespace Torch.Views
grid.Children.Add(text);
FrameworkElement valueControl;
if (descriptor?.EditorType != null)
{
valueControl = (FrameworkElement)Activator.CreateInstance(descriptor.EditorType);
valueControl.SetBinding(FrameworkElement.DataContextProperty, property.Name);
}
if (property.GetSetMethod() == null || descriptor?.ReadOnly == true)
{
valueControl = new TextBlock();
@@ -211,11 +216,21 @@ namespace Torch.Views
valueControl = button;
}
else if (propertyType.IsPrimitive || propertyType == typeof(string))
else if (propertyType.IsPrimitive)
{
valueControl = new TextBox();
valueControl.SetBinding(TextBox.TextProperty, property.Name);
}
else if (propertyType == typeof(string))
{
var tb = new TextBox();
tb.TextWrapping = TextWrapping.Wrap;
tb.AcceptsReturn = true;
tb.AcceptsTab = true;
tb.SpellCheck.IsEnabled = true;
tb.SetBinding(TextBox.TextProperty, property.Name);
valueControl = tb;
}
else
{
var button = new Button