From 5c2daaeb98806f75136db61e8e917b3a4ded5b7e Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 24 Jun 2025 10:59:58 +0200 Subject: [PATCH] =?UTF-8?q?Se=20a=C3=B1adi=C3=B3=20un=20estilo=20global=20?= =?UTF-8?q?para=20TreeViewItem=20en=20App.xaml=20para=20evitar=20errores?= =?UTF-8?q?=20de=20binding.=20Se=20actualizaron=20las=20referencias=20de?= =?UTF-8?q?=20paquetes=20en=20CtrEditor.csproj,=20cambiando=20la=20versi?= =?UTF-8?q?=C3=B3n=20de=20LiveChartsCore.SkiaSharpView.WPF=20y=20a=C3=B1ad?= =?UTF-8?q?iendo=20SkiaSharp.Views.WPF.=20Se=20mejor=C3=B3=20la=20gesti?= =?UTF-8?q?=C3=B3n=20de=20carga=20de=20im=C3=A1genes=20en=20osBase.cs=20y?= =?UTF-8?q?=20ucCustomImage.xaml.cs,=20implementando=20un=20manejo=20de=20?= =?UTF-8?q?errores=20m=C3=A1s=20robusto=20y=20estableciendo=20im=C3=A1gene?= =?UTF-8?q?s=20por=20defecto=20en=20caso=20de=20fallos.=20Se=20ajust=C3=B3?= =?UTF-8?q?=20el=20XAML=20de=20ucBoolTag=20para=20mejorar=20la=20conversi?= =?UTF-8?q?=C3=B3n=20de=20color.=20Se=20implement=C3=B3=20un=20convertidor?= =?UTF-8?q?=20seguro=20para=20ImageSource=20en=20StateSerializer.cs,=20mej?= =?UTF-8?q?orando=20la=20deserializaci=C3=B3n=20de=20im=C3=A1genes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml | 6 ++ CtrEditor.csproj | 3 +- ObjetosSim/Decorativos/ucCustomImage.xaml.cs | 97 ++++++++++++++++---- ObjetosSim/TagsSignals/ucBoolTag.xaml | 2 +- ObjetosSim/osBase.cs | 26 +++++- Serialization/StateSerializer.cs | 84 ++++++++++++++++- 6 files changed, 197 insertions(+), 21 deletions(-) diff --git a/App.xaml b/App.xaml index 80f30c2..7625f43 100644 --- a/App.xaml +++ b/App.xaml @@ -22,6 +22,12 @@ + + + diff --git a/CtrEditor.csproj b/CtrEditor.csproj index 0ee2c26..98e787c 100644 --- a/CtrEditor.csproj +++ b/CtrEditor.csproj @@ -85,8 +85,9 @@ - + + diff --git a/ObjetosSim/Decorativos/ucCustomImage.xaml.cs b/ObjetosSim/Decorativos/ucCustomImage.xaml.cs index 8525fb1..6b62d43 100644 --- a/ObjetosSim/Decorativos/ucCustomImage.xaml.cs +++ b/ObjetosSim/Decorativos/ucCustomImage.xaml.cs @@ -1,7 +1,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using LibS7Adv; using System.Windows; -using System.Windows.Controls; +using System.Windows.Controls; using System.Windows.Media; using CtrEditor.FuncionesBase; using System.ComponentModel; @@ -27,11 +27,42 @@ namespace CtrEditor.ObjetosSim } - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(ImageSource_oculta))] - [property: Description("Path to the image file")] - [property: Category("Image:")] - private string imagePath; + private string _imagePath; + + [Description("Path to the image file")] + [Category("Image:")] + 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("Flip the image horizontally")] @@ -48,16 +79,32 @@ namespace CtrEditor.ObjetosSim [ObservableProperty] public ImageSource imageSource_oculta; - partial void OnImagePathChanged(string value) + private void OnImagePathChanged(string value) { - if (!string.IsNullOrEmpty(value)) + try { - ImageSource_oculta = ImageFromPath(value); + if (!string.IsNullOrEmpty(value)) + { + ImageSource_oculta = ImageFromPath(value); + } + else + { + // Si no hay path, usar la imagen por defecto + ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); + } } - else + catch { - // Si no hay path, usar la imagen por defecto - ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); + // 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; + } } } @@ -82,14 +129,30 @@ namespace CtrEditor.ObjetosSim public override void ucLoaded() { base.ucLoaded(); - if (!string.IsNullOrEmpty(ImagePath)) + try { - ImageSource_oculta = ImageFromPath(ImagePath); + 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"); + } } - else + catch { - // Si no hay path al cargar, usar la imagen por defecto - ImageSource_oculta = ImageFromPath("/Icons/unselect.png"); + // 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; + } } } } diff --git a/ObjetosSim/TagsSignals/ucBoolTag.xaml b/ObjetosSim/TagsSignals/ucBoolTag.xaml index c80696b..8b937d9 100644 --- a/ObjetosSim/TagsSignals/ucBoolTag.xaml +++ b/ObjetosSim/TagsSignals/ucBoolTag.xaml @@ -27,7 +27,7 @@ Width="16" Height="25" VerticalAlignment="Center" HorizontalAlignment="Center" Background="{Binding Color, Converter={StaticResource ColorToBrushConverter}}" />