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}}" />