fix PropertyGrid readonly is not copyable (#516)

(cherry picked from commit 09ddad495988beed896077f879998bf62cd0c8a8)
This commit is contained in:
zznty
2022-11-10 23:37:21 +07:00
parent 8478ee3752
commit e8928b6b3b

View File

@@ -151,7 +151,7 @@ namespace Torch.Views
valueControl = (FrameworkElement)Activator.CreateInstance(descriptor.EditorType); valueControl = (FrameworkElement)Activator.CreateInstance(descriptor.EditorType);
valueControl.SetBinding(FrameworkElement.DataContextProperty, property.Name); valueControl.SetBinding(FrameworkElement.DataContextProperty, property.Name);
} }
else if (property.GetSetMethod() == null && !(propertyType.IsGenericType && typeof(ICollection).IsAssignableFrom(propertyType.GetGenericTypeDefinition()))|| descriptor?.ReadOnly == true) else if (property.GetSetMethod() == null && !(propertyType.IsGenericType && typeof(ICollection).IsAssignableFrom(propertyType.GetGenericTypeDefinition())))
{ {
valueControl = new TextBlock(); valueControl = new TextBlock();
var binding = new Binding(property.Name) var binding = new Binding(property.Name)
@@ -234,7 +234,10 @@ namespace Torch.Views
} }
else if (propertyType.IsPrimitive) else if (propertyType.IsPrimitive)
{ {
valueControl = new TextBox(); valueControl = new TextBox
{
IsReadOnly = descriptor?.ReadOnly == true
};
valueControl.SetBinding(TextBox.TextProperty, property.Name); valueControl.SetBinding(TextBox.TextProperty, property.Name);
} }
else if (propertyType == typeof(string)) else if (propertyType == typeof(string))
@@ -244,6 +247,7 @@ namespace Torch.Views
tb.AcceptsReturn = true; tb.AcceptsReturn = true;
tb.AcceptsTab = true; tb.AcceptsTab = true;
tb.SpellCheck.IsEnabled = true; tb.SpellCheck.IsEnabled = true;
tb.IsReadOnly = descriptor?.ReadOnly == true;
tb.SetBinding(TextBox.TextProperty, property.Name); tb.SetBinding(TextBox.TextProperty, property.Name);
valueControl = tb; valueControl = tb;
} }