TagViewModel.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.CmdPal.Core.ViewModels.Models; 6 using Microsoft.CommandPalette.Extensions; 7 8 namespace Microsoft.CmdPal.Core.ViewModels; 9 10 public partial class TagViewModel(ITag _tag, WeakReference<IPageContext> context) : ExtensionObjectViewModel(context) 11 { 12 private readonly ExtensionObject<ITag> _tagModel = new(_tag); 13 14 public string ToolTip => string.IsNullOrEmpty(ModelToolTip) ? Text : ModelToolTip; 15 16 // Remember - "observable" properties from the model (via PropChanged) 17 // cannot be marked [ObservableProperty] 18 public string Text { get; private set; } = string.Empty; 19 20 public string ModelToolTip { get; private set; } = string.Empty; 21 22 public OptionalColor Foreground { get; private set; } 23 24 public OptionalColor Background { get; private set; } 25 26 public IconInfoViewModel Icon { get; private set; } = new(null); 27 28 public override void InitializeProperties() 29 { 30 var model = _tagModel.Unsafe; 31 if (model is null) 32 { 33 return; 34 } 35 36 Text = model.Text; 37 Foreground = model.Foreground; 38 Background = model.Background; 39 ModelToolTip = model.ToolTip; 40 Icon = new(model.Icon); 41 Icon.InitializeProperties(); 42 43 UpdateProperty(nameof(Text)); 44 UpdateProperty(nameof(Foreground)); 45 UpdateProperty(nameof(Background)); 46 UpdateProperty(nameof(ToolTip)); 47 UpdateProperty(nameof(Icon)); 48 } 49 }