Trabajando con los decimales
This commit is contained in:
parent
a1ecfca034
commit
1ce0371d18
|
@ -166,20 +166,42 @@
|
|||
|
||||
<!-- PanelEdicion -->
|
||||
<xctk:PropertyGrid Grid.Row="2" Margin="5" x:Name="PanelEdicion" AutoGenerateProperties="False" SelectedObject="{Binding}">
|
||||
|
||||
<xctk:PropertyGrid.EditorDefinitions>
|
||||
|
||||
<!-- Velocidad -->
|
||||
<xctk:EditorTemplateDefinition TargetProperties="VelocidadActual">
|
||||
<xctk:EditorTemplateDefinition.EditingTemplate>
|
||||
<DataTemplate>
|
||||
<xctk:SingleUpDown Background="Beige" Text="{Binding Value, Converter={StaticResource floatFormatter}}"/>
|
||||
</DataTemplate>
|
||||
</xctk:EditorTemplateDefinition.EditingTemplate>
|
||||
</xctk:EditorTemplateDefinition>
|
||||
|
||||
<!-- Float -->
|
||||
<xctk:EditorTemplateDefinition>
|
||||
<xctk:EditorTemplateDefinition.TargetProperties>
|
||||
<xctk:TargetPropertyType Type="{x:Type sys:Single}" />
|
||||
</xctk:EditorTemplateDefinition.TargetProperties>
|
||||
<xctk:EditorTemplateDefinition.EditingTemplate>
|
||||
<DataTemplate>
|
||||
<TextBox Text="{Binding Value, Converter={StaticResource floatFormatter}}"/>
|
||||
<TextBox Text="{Binding Value, Converter={StaticResource floatFormatter}}"/>
|
||||
</DataTemplate>
|
||||
</xctk:EditorTemplateDefinition.EditingTemplate>
|
||||
</xctk:EditorTemplateDefinition>
|
||||
|
||||
<!-- Double -->
|
||||
<xctk:EditorTemplateDefinition>
|
||||
<xctk:EditorTemplateDefinition.TargetProperties>
|
||||
<xctk:TargetPropertyType Type="{x:Type sys:Double}" />
|
||||
</xctk:EditorTemplateDefinition.TargetProperties>
|
||||
<xctk:EditorTemplateDefinition.EditingTemplate>
|
||||
<DataTemplate>
|
||||
<TextBox Text="{Binding Value, Converter={StaticResource doubleFormatter}}"/>
|
||||
</DataTemplate>
|
||||
</xctk:EditorTemplateDefinition.EditingTemplate>
|
||||
</xctk:EditorTemplateDefinition>
|
||||
</xctk:PropertyGrid.EditorDefinitions>
|
||||
|
||||
</xctk:PropertyGrid.EditorDefinitions>
|
||||
</xctk:PropertyGrid>
|
||||
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ namespace CtrEditor.ObjetosSim
|
|||
public float min_OUT_Scaled;
|
||||
[ObservableProperty]
|
||||
public float max_OUT_Scaled;
|
||||
|
||||
[TypeConverter(typeof(FloatToStringConverter))]
|
||||
|
||||
[ObservableProperty]
|
||||
public float value;
|
||||
|
||||
|
|
|
@ -94,37 +94,6 @@ namespace CtrEditor.ObjetosSim
|
|||
.Cast<PropertyDescriptor>()
|
||||
.Where(prop => !prop.Attributes.OfType<HiddenAttribute>().Any());
|
||||
|
||||
|
||||
//// Create the DataTemplate for float and double editors
|
||||
//var doubleFactory = new FrameworkElementFactory(typeof(DoubleUpDown));
|
||||
//doubleFactory.SetValue(DoubleUpDown.FormatStringProperty, "F3");
|
||||
//doubleFactory.SetValue(DoubleUpDown.IncrementProperty, 0.001);
|
||||
//doubleFactory.SetValue(DoubleUpDown.MaximumProperty, 200000.599);
|
||||
//doubleFactory.SetBinding(DoubleUpDown.ValueProperty, new Binding("Value")
|
||||
//{
|
||||
// Mode = BindingMode.TwoWay,
|
||||
// UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
|
||||
//});
|
||||
|
||||
//var doubleTemplate = new DataTemplate { VisualTree = doubleFactory };
|
||||
|
||||
//// Add editor definitions for float and double
|
||||
//var floatEditorDefinition = new EditorDefinition
|
||||
//{
|
||||
// EditorTemplate = doubleTemplate,
|
||||
// TargetType = typeof(float)
|
||||
//};
|
||||
|
||||
//var doubleEditorDefinition = new EditorDefinition
|
||||
//{
|
||||
// EditorTemplate = doubleTemplate,
|
||||
// TargetType = typeof(double)
|
||||
//};
|
||||
|
||||
//propertyGrid.EditorDefinitions.Add(floatEditorDefinition);
|
||||
//propertyGrid.EditorDefinitions.Add(doubleEditorDefinition);
|
||||
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var displayNameAttr = property.Attributes.OfType<DisplayNameAttribute>().FirstOrDefault();
|
||||
|
|
|
@ -54,7 +54,6 @@ namespace CtrEditor.ObjetosSim
|
|||
}
|
||||
}
|
||||
|
||||
[TypeConverter(typeof(DoubleToStringConverter))]
|
||||
public abstract partial class osBase : ObservableObject
|
||||
{
|
||||
public virtual string Nombre { get; set; } = "osBase";
|
||||
|
|
|
@ -101,47 +101,6 @@ namespace CtrEditor
|
|||
DisplayName = displayName;
|
||||
}
|
||||
}
|
||||
public class DoubleToStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double doubleValue)
|
||||
{
|
||||
return doubleValue.ToString("0.00", culture);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string stringValue && double.TryParse(stringValue, NumberStyles.Float, culture, out double result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public class FloatToStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is float doubleValue)
|
||||
{
|
||||
return doubleValue.ToString("0.00", culture);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string stringValue && float.TryParse(stringValue, NumberStyles.Float, culture, out float result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public class StringToBrushConverter : IValueConverter
|
||||
{
|
||||
|
@ -404,14 +363,15 @@ namespace CtrEditor
|
|||
{
|
||||
if (value is float floatValue)
|
||||
{
|
||||
return floatValue.ToString("0.00", culture); // Formatear a dos decimales
|
||||
var r = floatValue.ToString("0.00", culture).Replace('.', ','); // Formatear a dos decimales
|
||||
return r;
|
||||
}
|
||||
return value; // Devolver el valor original si no es un float
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string stringValue && float.TryParse(stringValue, NumberStyles.Float, culture, out float result))
|
||||
if (value is string stringValue && float.TryParse(stringValue.Replace(',', '.'), NumberStyles.Float, culture, out float result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue