using CommunityToolkit.Mvvm.ComponentModel; using LibS7Adv; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using CtrEditor.FuncionesBase; using System.ComponentModel; using Newtonsoft.Json; namespace CtrEditor.ObjetosSim { /// /// A custom image control that can display an image from a file path /// public partial class osCustomImage : osBase, IosBase { public static string NombreClase() { return "Imagen Personalizada"; } private string nombre = NombreClase(); [property: Category("Identificación")] [property: Description("Nombre identificativo del objeto")] [property: Name("Nombre")] public override string Nombre { get => nombre; set => SetProperty(ref nombre, value); } private string _imagePath; [Description("Ruta del archivo de imagen")] [Category("Configuración")] [property: Name("Ruta de Imagen")] public string ImagePath { get => _imagePath; set { try { if (SetProperty(ref _imagePath, value)) { OnImagePathChanged(value); OnPropertyChanged(nameof(ImageSource_oculta)); } } catch { // Si hay error al establecer la propiedad, simplemente ignorarlo // y establecer la imagen por defecto try { SetProperty(ref _imagePath, value); ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); OnPropertyChanged(nameof(ImageSource_oculta)); } catch { // En caso de error total, establecer valores seguros _imagePath = value; ImageSource_oculta = null; } } } } [ObservableProperty] [property: Description("Voltear la imagen horizontalmente")] [property: Category("Configuración")] [property: Name("Voltear Horizontal")] private bool horizontal_Flip; [ObservableProperty] [property: Description("Voltear la imagen verticalmente")] [property: Category("Configuración")] [property: Name("Voltear Vertical")] private bool vertical_Flip; [ObservableProperty] [property: JsonIgnore] [property: Category("Apariencia")] [property: Description("Imagen visual del objeto")] [property: Name("Imagen")] public ImageSource imageSource_oculta; private void OnImagePathChanged(string value) { try { if (!string.IsNullOrEmpty(value)) { ImageSource_oculta = ImageFromPath(value); } else { // Si no hay path, usar la imagen por defecto ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); } } catch { // Si hay cualquier error, usar la imagen por defecto try { ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); } catch { // Si incluso la imagen por defecto falla, establecer como null ImageSource_oculta = null; } } } partial void OnHorizontal_FlipChanged(bool value) { // Property changed handler will trigger UI update through binding } partial void OnVertical_FlipChanged(bool value) { // Property changed handler will trigger UI update through binding } public osCustomImage() { Ancho = 0.30f; Alto = 0.30f; // Establecer la imagen por defecto al crear el objeto ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); } public override void ucLoaded() { base.ucLoaded(); try { if (!string.IsNullOrEmpty(ImagePath)) { ImageSource_oculta = ImageFromPath(ImagePath); } else { // Si no hay path al cargar, usar la imagen por defecto ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); } } catch { // Si hay cualquier error, usar la imagen por defecto try { ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); } catch { // Si incluso la imagen por defecto falla, establecer como null ImageSource_oculta = null; } } } } public partial class ucCustomImage : UserControl, IDataContainer { public osBase? Datos { get; set; } public int zIndex_fromFrames { get; set; } public ucCustomImage() { InitializeComponent(); this.Loaded += OnLoaded; this.Unloaded += OnUnloaded; } private void OnLoaded(object sender, RoutedEventArgs e) { Datos?.ucLoaded(); } private void OnUnloaded(object sender, RoutedEventArgs e) { Datos?.ucUnLoaded(); } public void Highlight(bool State) { } public ZIndexEnum ZIndex_Base() { return ZIndexEnum.Estaticos; } } }