From dd2b656c69cfc7e8faed4d028c69ea127c68c5aa Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 4 May 2024 21:27:04 +0200 Subject: [PATCH] Falta terminar el highlight --- MainViewModel.cs | 16 ++++++++++++++- MainWindow.xaml | 4 +++- MainWindow.xaml.cs | 31 ++++++++++++++++++----------- ObjetosSim/osBase.cs | 1 + ObjetosSim/ucBotella.xaml | 2 +- ObjetosSim/ucBotella.xaml.cs | 1 + ObjetosSim/ucTransporteTTop.xaml | 13 ++++++------ ObjetosSim/ucTransporteTTop.xaml.cs | 1 + 8 files changed, 48 insertions(+), 21 deletions(-) diff --git a/MainViewModel.cs b/MainViewModel.cs index 21b5f7d..aaa6b64 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -171,7 +171,21 @@ namespace CtrEditor OnPropertyChanged(nameof(SelectedImage)); } } - + + private osBase _selectedItemOsList; + public osBase SelectedItemOsList + { + get => _selectedItemOsList; + set + { + if (_selectedItemOsList != value) + { + _selectedItemOsList = value; + OnPropertyChanged(nameof(SelectedItemOsList)); + } + } + } + public ICommand OpenWorkDirectoryCommand { get; } private void OpenWorkDirectory() diff --git a/MainWindow.xaml b/MainWindow.xaml index 4c875c3..6de6195 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -72,7 +72,9 @@ + ItemsSource="{Binding ObjetosSimulables}" DisplayMemberPath="Nombre" + SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}" + SelectionChanged="ListaOs_SelectionChanged"/> diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index ff5fdf0..b102b1b 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; +using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -10,6 +11,11 @@ using System.Windows.Navigation; using System.Windows.Shapes; using CtrEditor.ObjetosSim; using static System.Runtime.InteropServices.JavaScript.JSType; +using Binding = System.Windows.Data.Binding; +using Label = System.Windows.Controls.Label; +using MouseEventArgs = System.Windows.Input.MouseEventArgs; +using TextBox = System.Windows.Controls.TextBox; +using UserControl = System.Windows.Controls.UserControl; namespace CtrEditor { @@ -116,6 +122,15 @@ namespace CtrEditor userControl.CaptureMouse(); // Importante para recibir eventos de movimiento incluso fuera del control _isMovingUserControl = true; + if (sender is UserControl control && control.DataContext is osBase datos) + { + var viewModel = DataContext as MainViewModel; + if (viewModel != null) + { + viewModel.SelectedItemOsList = datos; // Esto desencadenará ListaOs_SelectionChanged + } + } + // ROTACION if (Keyboard.IsKeyDown(Key.LeftShift)) { @@ -258,26 +273,18 @@ namespace CtrEditor _startPointUserControl = currentPosition; } - - private void UserControl_MouseEnter(object sender, MouseEventArgs e) { - // Lógica a ejecutar cuando el mouse entra en el UserControl if (sender is UserControl userControl) - { - // Por ejemplo, cambiar el color de fondo para indicar el foco - userControl.Background = Brushes.LightBlue; - } + if (userControl is IDataContainer dataContainer) + dataContainer.Highlight(true); } private void UserControl_MouseLeave(object sender, MouseEventArgs e) { - // Lógica a ejecutar cuando el mouse sale del UserControl if (sender is UserControl userControl) - { - // Restaurar el color de fondo original - userControl.Background = Brushes.White; - } + if (userControl is IDataContainer dataContainer) + dataContainer.Highlight(false); } private void ViewModel_ImageSelected(object sender, string imagePath) diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs index 7a2361a..2d087be 100644 --- a/ObjetosSim/osBase.cs +++ b/ObjetosSim/osBase.cs @@ -23,6 +23,7 @@ namespace CtrEditor.ObjetosSim void Resize(double width, double height); void Move(double Left, double Top); void Rotate(double Angle); + void Highlight(bool State); } public abstract class osBase : INotifyPropertyChanged, IosBase diff --git a/ObjetosSim/ucBotella.xaml b/ObjetosSim/ucBotella.xaml index f15fcde..3d043f8 100644 --- a/ObjetosSim/ucBotella.xaml +++ b/ObjetosSim/ucBotella.xaml @@ -2,5 +2,5 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding RelativeSource={RelativeSource Self}}"> - + \ No newline at end of file diff --git a/ObjetosSim/ucBotella.xaml.cs b/ObjetosSim/ucBotella.xaml.cs index c5901ee..fcd191d 100644 --- a/ObjetosSim/ucBotella.xaml.cs +++ b/ObjetosSim/ucBotella.xaml.cs @@ -50,6 +50,7 @@ namespace CtrEditor.ObjetosSim } } public void Rotate(double Angle) { } + public void Highlight(bool State) { } } } diff --git a/ObjetosSim/ucTransporteTTop.xaml b/ObjetosSim/ucTransporteTTop.xaml index 5793473..773720f 100644 --- a/ObjetosSim/ucTransporteTTop.xaml +++ b/ObjetosSim/ucTransporteTTop.xaml @@ -5,12 +5,13 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CtrEditor" mc:Ignorable="d"> - - - - - - + + + + + + + diff --git a/ObjetosSim/ucTransporteTTop.xaml.cs b/ObjetosSim/ucTransporteTTop.xaml.cs index 8eb02de..86dfd4e 100644 --- a/ObjetosSim/ucTransporteTTop.xaml.cs +++ b/ObjetosSim/ucTransporteTTop.xaml.cs @@ -94,6 +94,7 @@ namespace CtrEditor.ObjetosSim if (Datos is osTransporteTTop datos) datos.Angulo = Angle; } + public void Highlight(bool State) { } } }