Mejorado de CargarPropiedadesosDatos
This commit is contained in:
parent
c1ac20964e
commit
667cd18f5d
1
App.xaml
1
App.xaml
|
@ -15,6 +15,7 @@
|
|||
<local:BrushToColorNameConverter x:Key="BrushToColorNameConverter"/>
|
||||
<local:VerticalPositionConverter x:Key="VerticalPositionConverter"/>
|
||||
<local:SumConverter x:Key="SumConverter" />
|
||||
<local:StringToBrushConverter x:Key="StringToBrushConverter"/>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
|
||||
|
|
|
@ -67,20 +67,22 @@
|
|||
AnchoCentro="{Binding AnchoCentral, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||
Canvas.Top="{Binding Distance, Converter={StaticResource MeterToPixelConverter},ConverterParameter=-1}"
|
||||
/>
|
||||
Canvas.Top="{Binding Distance, Converter={StaticResource MeterToPixelConverter},ConverterParameter=-1}"
|
||||
Color="Blue"/>
|
||||
|
||||
<uc:ThreeLinesControl x:Name="GuiaInferior" AnchoRecto="{Binding AnchoRecto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||
AnchoCentro="{Binding AnchoCentral, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}">
|
||||
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||
Color="Blue">
|
||||
|
||||
<Canvas.Top>
|
||||
<MultiBinding Converter="{StaticResource SumConverter}">
|
||||
<Binding Path="Alto" Converter="{StaticResource MeterToPixelConverter}" ConverterParameter="1.0" />
|
||||
<Binding Path="Distance" Converter="{StaticResource MeterToPixelConverter}" ConverterParameter="1.0" />
|
||||
</MultiBinding>
|
||||
</Canvas.Top>
|
||||
</uc:ThreeLinesControl>
|
||||
</uc:ThreeLinesControl>
|
||||
</Canvas>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
@ -35,6 +35,9 @@ namespace CtrEditor.ObjetosSim
|
|||
set => SetProperty(ref nombre, value);
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
string color;
|
||||
|
||||
[ObservableProperty]
|
||||
public string motorA;
|
||||
|
||||
|
|
|
@ -30,6 +30,13 @@ namespace CtrEditor.ObjetosSim
|
|||
public bool tipo_NC;
|
||||
[ObservableProperty]
|
||||
private Brush color;
|
||||
|
||||
partial void OnColorChanged(Brush value)
|
||||
{
|
||||
OnEstadoChanged(Estado);
|
||||
}
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private Brush colorButton_oculto;
|
||||
[ObservableProperty]
|
||||
|
|
|
@ -8,6 +8,8 @@ using System.Windows;
|
|||
using System.Windows.Media;
|
||||
using CtrEditor.ObjetosSim.UserControls;
|
||||
using System.Collections;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
|
@ -76,10 +78,11 @@ namespace CtrEditor.ObjetosSim
|
|||
}
|
||||
|
||||
|
||||
|
||||
public static void CargarPropiedadesosDatos(Object selectedObject, StackPanel PanelEdicion, ResourceDictionary Resources)
|
||||
{
|
||||
PanelEdicion.Children.Clear();
|
||||
var properties = selectedObject.GetType().GetProperties();
|
||||
var properties = selectedObject.GetType().GetProperties().OrderBy(p => p.Name); // Ordenar alfabéticamente
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
|
@ -93,117 +96,172 @@ namespace CtrEditor.ObjetosSim
|
|||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
||||
|
||||
var label = new Label
|
||||
{
|
||||
Content = property.Name.Replace("_", " ") + ":",
|
||||
Margin = new Thickness(0, 0, 5, 0),
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
Grid.SetColumn(label, 0);
|
||||
grid.Children.Add(label);
|
||||
|
||||
if (property.PropertyType == typeof(double) || property.PropertyType == typeof(float) || property.PropertyType == typeof(string) || property.PropertyType == typeof(int))
|
||||
{
|
||||
var textBox = new TextBox
|
||||
{
|
||||
Content = property.Name.Replace("_", " ") + ":",
|
||||
Margin = new Thickness(0, 0, 5, 0),
|
||||
Margin = new Thickness(0),
|
||||
MinWidth = 200,
|
||||
VerticalContentAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay,
|
||||
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
|
||||
};
|
||||
|
||||
if (property.PropertyType == typeof(float))
|
||||
{
|
||||
if (Application.Current.Resources.Contains("floatFormatter"))
|
||||
{
|
||||
binding.Converter = Application.Current.Resources["floatFormatter"] as IValueConverter;
|
||||
}
|
||||
}
|
||||
if (property.PropertyType == typeof(double))
|
||||
{
|
||||
if (Application.Current.Resources.Contains("doubleFormatter"))
|
||||
{
|
||||
binding.Converter = Application.Current.Resources["doubleFormatter"] as IValueConverter;
|
||||
}
|
||||
}
|
||||
|
||||
textBox.SetBinding(TextBox.TextProperty, binding);
|
||||
|
||||
textBox.KeyDown += (sender, e) =>
|
||||
{
|
||||
if (e.Key == Key.Enter || e.Key == Key.Down)
|
||||
{
|
||||
var request = new TraversalRequest(FocusNavigationDirection.Next);
|
||||
request.Wrapped = true;
|
||||
textBox.MoveFocus(request);
|
||||
}
|
||||
else if (e.Key == Key.Up)
|
||||
{
|
||||
var request = new TraversalRequest(FocusNavigationDirection.Previous);
|
||||
request.Wrapped = true;
|
||||
textBox.MoveFocus(request);
|
||||
}
|
||||
};
|
||||
|
||||
Grid.SetColumn(textBox, 1);
|
||||
grid.Children.Add(textBox);
|
||||
}
|
||||
else if (property.PropertyType == typeof(bool))
|
||||
{
|
||||
var checkBox = new CheckBox
|
||||
{
|
||||
Margin = new Thickness(5, 0, 0, 0),
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
Grid.SetColumn(label, 0);
|
||||
grid.Children.Add(label);
|
||||
|
||||
if (property.PropertyType == typeof(double) || property.PropertyType == typeof(float) || property.PropertyType == typeof(string) || property.PropertyType == typeof(int))
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
var textBox = new TextBox
|
||||
{
|
||||
Margin = new Thickness(0),
|
||||
MinWidth = 200,
|
||||
VerticalContentAlignment = VerticalAlignment.Center
|
||||
};
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay
|
||||
};
|
||||
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay,
|
||||
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
|
||||
};
|
||||
checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
|
||||
|
||||
if (property.PropertyType == typeof(float))
|
||||
checkBox.KeyDown += (sender, e) =>
|
||||
{
|
||||
if (e.Key == Key.Enter || e.Key == Key.Down)
|
||||
{
|
||||
if (Resources != null)
|
||||
binding.Converter = (FloatToFormattedStringConverter)Resources["floatFormatter"];
|
||||
var request = new TraversalRequest(FocusNavigationDirection.Next);
|
||||
request.Wrapped = true;
|
||||
checkBox.MoveFocus(request);
|
||||
}
|
||||
if (property.PropertyType == typeof(double))
|
||||
else if (e.Key == Key.Up)
|
||||
{
|
||||
if (Resources != null)
|
||||
binding.Converter = (DoubleToFormattedStringConverter)Resources["doubleFormatter"];
|
||||
var request = new TraversalRequest(FocusNavigationDirection.Previous);
|
||||
request.Wrapped = true;
|
||||
checkBox.MoveFocus(request);
|
||||
}
|
||||
};
|
||||
|
||||
textBox.SetBinding(TextBox.TextProperty, binding);
|
||||
|
||||
Grid.SetColumn(textBox, 1);
|
||||
grid.Children.Add(textBox);
|
||||
}
|
||||
else if (property.PropertyType == typeof(bool))
|
||||
{
|
||||
var checkBox = new CheckBox
|
||||
{
|
||||
Margin = new Thickness(5, 0, 0, 0),
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay
|
||||
};
|
||||
|
||||
checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
|
||||
|
||||
Grid.SetColumn(checkBox, 1);
|
||||
grid.Children.Add(checkBox);
|
||||
}
|
||||
else if (property.PropertyType == typeof(Brush))
|
||||
{
|
||||
var listBox = new ListBox
|
||||
{
|
||||
ItemsSource = new List<string> { "Rojo", "Azul", "Negro", "Verde", "Gris" },
|
||||
Margin = new Thickness(0),
|
||||
MinWidth = 200
|
||||
};
|
||||
|
||||
listBox.SelectionChanged += (sender, e) =>
|
||||
{
|
||||
if (listBox.SelectedItem != null)
|
||||
{
|
||||
switch (listBox.SelectedItem.ToString())
|
||||
{
|
||||
case "Rojo":
|
||||
property.SetValue(selectedObject, Brushes.Red);
|
||||
break;
|
||||
case "Azul":
|
||||
property.SetValue(selectedObject, Brushes.Blue);
|
||||
break;
|
||||
case "Negro":
|
||||
property.SetValue(selectedObject, Brushes.Black);
|
||||
break;
|
||||
case "Verde":
|
||||
property.SetValue(selectedObject, Brushes.Green);
|
||||
break;
|
||||
case "Gris":
|
||||
property.SetValue(selectedObject, Brushes.Gray);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay,
|
||||
Converter = new BrushToColorNameConverter()
|
||||
};
|
||||
|
||||
listBox.SetBinding(ListBox.SelectedItemProperty, binding);
|
||||
|
||||
Grid.SetColumn(listBox, 1);
|
||||
grid.Children.Add(listBox);
|
||||
}
|
||||
PanelEdicion.Children.Add(grid);
|
||||
Grid.SetColumn(checkBox, 1);
|
||||
grid.Children.Add(checkBox);
|
||||
}
|
||||
}
|
||||
else if (property.PropertyType == typeof(Brush))
|
||||
{
|
||||
var comboBox = new ComboBox
|
||||
{
|
||||
ItemsSource = new List<Tuple<string, SolidColorBrush>>
|
||||
{
|
||||
Tuple.Create("Rojo", Brushes.Red),
|
||||
Tuple.Create("Azul", Brushes.Blue),
|
||||
Tuple.Create("Negro", Brushes.Black),
|
||||
Tuple.Create("Verde", Brushes.Green),
|
||||
Tuple.Create("Gris", Brushes.Gray)
|
||||
},
|
||||
SelectedValuePath = "Item2",
|
||||
Margin = new Thickness(0),
|
||||
MinWidth = 200
|
||||
};
|
||||
|
||||
public static List<string> CargarPropiedadesosDatosTags(Object selectedObject, StackPanel PanelEdicion, ResourceDictionary Resources)
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
Source = selectedObject,
|
||||
Mode = BindingMode.TwoWay,
|
||||
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
|
||||
};
|
||||
|
||||
comboBox.SetBinding(ComboBox.SelectedValueProperty, binding);
|
||||
|
||||
comboBox.KeyDown += (sender, e) =>
|
||||
{
|
||||
if (e.Key == Key.Enter || e.Key == Key.Down)
|
||||
{
|
||||
var request = new TraversalRequest(FocusNavigationDirection.Next);
|
||||
request.Wrapped = true;
|
||||
comboBox.MoveFocus(request);
|
||||
}
|
||||
else if (e.Key == Key.Up)
|
||||
{
|
||||
var request = new TraversalRequest(FocusNavigationDirection.Previous);
|
||||
request.Wrapped = true;
|
||||
comboBox.MoveFocus(request);
|
||||
}
|
||||
};
|
||||
|
||||
var template = new DataTemplate();
|
||||
var stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel));
|
||||
stackPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
|
||||
|
||||
var rectangleFactory = new FrameworkElementFactory(typeof(Rectangle));
|
||||
rectangleFactory.SetValue(Rectangle.WidthProperty, 16.0);
|
||||
rectangleFactory.SetValue(Rectangle.HeightProperty, 16.0);
|
||||
rectangleFactory.SetBinding(Rectangle.FillProperty, new Binding("Item2"));
|
||||
stackPanelFactory.AppendChild(rectangleFactory);
|
||||
|
||||
var textBlockFactory = new FrameworkElementFactory(typeof(TextBlock));
|
||||
textBlockFactory.SetBinding(TextBlock.TextProperty, new Binding("Item1"));
|
||||
stackPanelFactory.AppendChild(textBlockFactory);
|
||||
|
||||
template.VisualTree = stackPanelFactory;
|
||||
comboBox.ItemTemplate = template;
|
||||
|
||||
Grid.SetColumn(comboBox, 1);
|
||||
grid.Children.Add(comboBox);
|
||||
}
|
||||
PanelEdicion.Children.Add(grid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<string> CargarPropiedadesosDatosTags(Object selectedObject, StackPanel PanelEdicion, ResourceDictionary Resources)
|
||||
{
|
||||
PanelEdicion.Children.Clear();
|
||||
var properties = selectedObject.GetType().GetProperties();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
@ -8,6 +9,10 @@ namespace CtrEditor.ObjetosSim.UserControls
|
|||
/// <summary>
|
||||
/// Interaction logic for ThreeLinesControl.xaml
|
||||
/// </summary>
|
||||
///
|
||||
|
||||
|
||||
[ObservableObject]
|
||||
public partial class ThreeLinesControl : UserControl
|
||||
{
|
||||
private Rectangle _liz;
|
||||
|
@ -18,6 +23,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
|||
{
|
||||
InitializeComponent();
|
||||
this.Loaded += ThreeLinesControl_Loaded;
|
||||
Color = Brushes.Gray;
|
||||
}
|
||||
|
||||
private void ThreeLinesControl_Loaded(object sender, RoutedEventArgs e)
|
||||
|
@ -25,6 +31,9 @@ namespace CtrEditor.ObjetosSim.UserControls
|
|||
CreateOrUpdateRectangles();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private Brush color;
|
||||
|
||||
public double AnchoRecto
|
||||
{
|
||||
get { return (double)GetValue(AnchoRectoProperty); }
|
||||
|
@ -76,7 +85,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
|||
{
|
||||
Width = AnchoRecto,
|
||||
Height = AltoGuia,
|
||||
Fill = Brushes.Blue
|
||||
Fill = Color
|
||||
};
|
||||
Canvas.SetLeft(_liz, 0);
|
||||
Canvas.SetTop(_liz, -AltoGuia / 2);
|
||||
|
@ -87,7 +96,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
|||
{
|
||||
Width = CalculateLcWidth(),
|
||||
Height = AltoGuia,
|
||||
Fill = Brushes.Red,
|
||||
Fill = Color,
|
||||
RenderTransformOrigin = new Point(0, 0.5)
|
||||
};
|
||||
_lc.RenderTransform = new RotateTransform(GetRotationAngle(AnchoCentro, Altura));
|
||||
|
@ -100,7 +109,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
|||
{
|
||||
Width = AnchoRecto,
|
||||
Height = AltoGuia,
|
||||
Fill = Brushes.Green
|
||||
Fill = Color
|
||||
};
|
||||
Canvas.SetLeft(_lde, AnchoRecto + AnchoCentro);
|
||||
Canvas.SetTop(_lde, Altura - AltoGuia / 2);
|
||||
|
|
|
@ -447,7 +447,7 @@ namespace CtrEditor.Simulacion
|
|||
Body.SetFriction(0.2f);
|
||||
|
||||
// Configurar amortiguamiento
|
||||
Body.LinearDamping = 1f; // Ajustar para controlar la reducción de la velocidad lineal
|
||||
Body.LinearDamping = 3f; // Ajustar para controlar la reducción de la velocidad lineal
|
||||
Body.AngularDamping = 1f; // Ajustar para controlar la reducción de la velocidad angular
|
||||
Body.SetRestitution(0f); // Baja restitución para menos rebote
|
||||
|
||||
|
|
|
@ -5,6 +5,22 @@ using System.Windows;
|
|||
|
||||
namespace CtrEditor
|
||||
{
|
||||
public class StringToBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string colorString)
|
||||
{
|
||||
return (Brush)new BrushConverter().ConvertFromString(colorString);
|
||||
}
|
||||
return Brushes.Transparent;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public class SumConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
|
|
Loading…
Reference in New Issue