fix edit page loading

This commit is contained in:
kwan.nguyen 2024-10-30 18:57:04 +07:00
parent 5e1344d9d5
commit 05a0eab829
5 changed files with 20 additions and 9 deletions

View File

@ -35,7 +35,7 @@
ManipulationMode="TranslateX,TranslateY" ManipulationDelta="MainScroll_ManipulationDelta"
Loading="MainScroll_Loading">
<Viewbox Width="{Binding Width, Source={StaticResource previewStyle}, Mode=OneWay}" Height="{Binding Height, Source={StaticResource previewStyle}, Mode=OneWay}">
<Image x:Name="MainPreview" Source="{x:Bind PreviewModel.Source, Mode=OneWay}" ImageOpened="Image_Loaded">
<Image x:Name="MainPreview" Source="{x:Bind PreviewModel.Source, Mode=OneWay}">
<Image.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="MainPreviewRefresh" Text="Refresh" Click="MainPreviewRefresh_Click" />
@ -76,7 +76,6 @@
Source="{x:Bind Source, Mode=OneWay}"
Opacity="{x:Bind Deleted, Mode=OneWay, Converter={StaticResource opacityConverter}}"
Tapped="Image_Tapped"
ImageOpened="Image_Loaded"
Tag="{x:Bind Id}">
<Image.ContextFlyout>
<MenuFlyout>

View File

@ -12,6 +12,7 @@ using PCUT.ViewModels;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@ -86,9 +87,9 @@ namespace PCUT.Pages
if (_svgData.Data != null)
{
LoadingModel.SetCount(_svgData.ComponentCount + dataUnloaded);
PreviewModel.SetSource(_svgData.Data);
PreviewModel.SetSource(_svgData.Data, Image_Loaded);
foreach (var (id, deleted, component) in _svgData.ComponentData)
ComponentModel.AddSource(id, deleted, component);
ComponentModel.AddSource(id, deleted, component, Image_Loaded);
}
if (!UserContext.Instance.IsPermittedEdit)
_designCenterModel.SelectedHeightIndex = 0;
@ -157,9 +158,10 @@ namespace PCUT.Pages
((ComponentStyle)Resources["componentStyle"]).SetSize(ComponentColumnDefinition, rate: 3);
}
private void Image_Loaded(object sender, RoutedEventArgs e)
private void Image_Loaded(SvgImageSource sender, SvgImageSourceOpenedEventArgs e)
{
LoadingModel.DecreaseCount();
sender.Opened -= Image_Loaded;
}
private void AllImageLoaded(object sender, PropertyChangedEventArgs e)

View File

@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml.Linq;
using PCUT.Extensions;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
@ -13,9 +14,13 @@ namespace PCUT.ViewModels
{
public ObservableCollection<ComponentImageSource> ComponentList { get; } = new ObservableCollection<ComponentImageSource>();
public void AddSource(string id, bool deleted, XDocument doc)
public void AddSource(string id, bool deleted, XDocument doc, TypedEventHandler<SvgImageSource, SvgImageSourceOpenedEventArgs> eventHandler = null)
{
var source = new SvgImageSource();
if (eventHandler != null)
{
source.Opened += eventHandler;
}
ComponentList.Add(new ComponentImageSource { Id = id, Deleted = deleted, Source = source });
_ = source.LoadSvgAsync(doc);
}

View File

@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Xml.Linq;
using PCUT.Extensions;
using Windows.Foundation;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
@ -11,7 +12,7 @@ namespace PCUT.ViewModels
public event PropertyChangedEventHandler PropertyChanged;
private ImageSource _source;
private ImageSource _defaultSource = new SvgImageSource();
private SvgImageSource _defaultSource = new SvgImageSource();
public ImageSource Source
{
@ -31,9 +32,13 @@ namespace PCUT.ViewModels
Source = source;
}
public void SetSource(XDocument doc)
public void SetSource(XDocument doc, TypedEventHandler<SvgImageSource, SvgImageSourceOpenedEventArgs> eventHandler = null)
{
Source = _defaultSource;
if (eventHandler != null)
{
_defaultSource.Opened += eventHandler;
}
if (doc != null)
_ = _source.LoadSvgAsync(doc);
}

View File

@ -8,7 +8,7 @@ namespace PCUT.ViewModels
public event PropertyChangedEventHandler PropertyChanged;
private int _count;
public int Count { get; }
public int Count { get => _count; }
public void SetCount(int count)
{