Skip to content

Commit

Permalink
取消ViewModel Reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Poker-sang committed Nov 15, 2022
1 parent d0c1246 commit 5617ca7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 73 deletions.
1 change: 0 additions & 1 deletion TagsTree/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TagsTree.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:CommunityToolkit.WinUI.UI"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Border
Expand Down
7 changes: 4 additions & 3 deletions TagsTree/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Linq;
using System.Threading.Tasks;
using TagsTree.Services;
using TagsTree.Views;
Expand All @@ -18,8 +19,8 @@ public MainWindow()
// 加载窗口后设置标题,拖拽区域才能达到原定效果
ExtendsContentIntoTitleBar = true;
SetTitleBar(AppTitleBar);
Title = "TagsTree";

Title = nameof(TagsTree);
// TODO: Microsoft.WindowsAppSDK 1.2后,最小化的NavigationView没有高度
App.RootNavigationView = NavigationView;
App.RootFrame = NavigateFrame;
}
Expand Down Expand Up @@ -49,7 +50,7 @@ public async Task ConfigIsSet()

IconsHelper.LoadFilesIcons();

foreach (NavigationViewItem menuItem in NavigationView.MenuItems)
foreach (var menuItem in NavigationView.MenuItems.Cast<NavigationViewItem>())
menuItem.IsEnabled = true;
((NavigationViewItem)NavigationView.FooterMenuItems[0]).IsEnabled = await App.ChangeFilesObserver();
}
Expand Down
1 change: 1 addition & 0 deletions TagsTree/TagsTree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AssemblyName>TagsTree</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<NoWarn>1701;1702;CA1416</NoWarn>
Expand Down
16 changes: 0 additions & 16 deletions TagsTree/ViewModels/FileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ public FileViewModel(FileModel fileModel, TagViewModel? tag = null)
/// <param name="fullName">文件路径</param>
public FileViewModel(string fullName) => FileModel = new(-1, fullName.GetName(), fullName.GetPath());

/*
public new void Reload(string fullName)
{
base.Reload(fullName);
// 更新UI
GetFileModel().Reload(fullName);
OnPropertyChanged(nameof(Name));
OnPropertyChanged(nameof(Extension));
OnPropertyChanged(nameof(Path));
OnPropertyChanged(nameof(PartialPath));
OnPropertyChanged(nameof(Icon));
OnPropertyChanged(nameof(DateOfModification));
OnPropertyChanged(nameof(Size));
}
*/

private readonly WeakReference<FileSystemInfo?> _fileSystemInfo = new(null);

#region FileModel
Expand Down
101 changes: 53 additions & 48 deletions TagsTree/Views/FilePropertiesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:local="using:TagsTree.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:CommunityToolkit.WinUI.UI"
xmlns:uiControls="using:CommunityToolkit.WinUI.UI.Controls"
Background="Transparent"
NavigationCacheMode="Required"
Expand Down Expand Up @@ -57,52 +56,58 @@
ToolTipService.ToolTip="删除" />
</CommandBar>
</uiControls:DockPanel>
<StackPanel Orientation="Vertical">
<Image Width="64" Source="{x:Bind FileViewModel.Icon, Mode=OneWay}" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="名称"
Header="{x:Bind FileViewModel.Name, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="路径"
Header="{x:Bind FileViewModel.PartialPath, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="类型"
Header="{x:Bind FileViewModel.Extension, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="标签"
Header="{x:Bind FileViewModel.Tags, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="修改日期"
Header="{x:Bind FileViewModel.DateOfModification, Mode=OneWay}"
IsClickEnabled="True"
IsEnabled="{x:Bind FileViewModel.Exists, Mode=OneWay}"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="大小"
Header="{x:Bind FileViewModel.Size, Mode=OneWay}"
IsClickEnabled="True"
IsEnabled="{x:Bind FileViewModel.Exists, Mode=OneWay}"
Tapped="CopyClick" />
</StackPanel>
<ScrollViewer>
<StackPanel Orientation="Vertical">
<Rectangle Height="32" />
<Image Width="64" Source="{x:Bind FileViewModel.Icon, Mode=OneWay}" />
<Rectangle Height="32" />
<StackPanel Orientation="Vertical">
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="名称"
Header="{x:Bind FileViewModel.Name, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="路径"
Header="{x:Bind FileViewModel.PartialPath, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="类型"
Header="{x:Bind FileViewModel.Extension, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="标签"
Header="{x:Bind FileViewModel.Tags, Mode=OneWay}"
IsClickEnabled="True"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="修改日期"
Header="{x:Bind FileViewModel.DateOfModification, Mode=OneWay}"
IsClickEnabled="True"
IsEnabled="{x:Bind FileViewModel.Exists, Mode=OneWay}"
Tapped="CopyClick" />
<labs:SettingsCard
ActionIcon="Copy"
ActionIconToolTip="复制到剪切板"
Description="大小"
Header="{x:Bind FileViewModel.Size, Mode=OneWay}"
IsClickEnabled="True"
IsEnabled="{x:Bind FileViewModel.Exists, Mode=OneWay}"
Tapped="CopyClick" />
</StackPanel>
</StackPanel>
</ScrollViewer>
</uiControls:DockPanel>
</Page>
8 changes: 4 additions & 4 deletions TagsTree/Views/FilePropertiesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public partial class FilePropertiesPage : Page
{
public FilePropertiesPage() => InitializeComponent();

private static readonly FileViewModel ConstFileViewModel = new(App.IdFile[0]);
private static readonly FileViewModel _constFileViewModel = new("");

public FileViewModel FileViewModel { get; private set; } = ConstFileViewModel;
public FileViewModel FileViewModel { get; private set; } = _constFileViewModel;

#region 事件处理

Expand Down Expand Up @@ -58,7 +58,7 @@ private async void RenameBClick(object sender, RoutedEventArgs e)
var newFullName = FileViewModel.Path + @"\" + InputName.Text;
FileViewModel.FileModel.Rename(newFullName);
FileViewModel.MoveOrRenameAndSave(newFullName);
Load(FileViewModel);
OnPropertyChanged(nameof(FileViewModel));
}
private async void MoveBClick(object sender, RoutedEventArgs e)
{
Expand All @@ -85,7 +85,7 @@ private async void MoveBClick(object sender, RoutedEventArgs e)

FileViewModel.FileModel.Move(newFullName);
FileViewModel.MoveOrRenameAndSave(newFullName);
Load(FileViewModel);
OnPropertyChanged(nameof(FileViewModel));
}
private async void DeleteBClick(object sender, RoutedEventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion TagsTree/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ToggleSwitch x:Name="CbRootFoldersExist" />
</labs:SettingsCard>
<labs:SettingsCard
Description="监控文件"
Description="监控文件路径文件下文件(夹)的变化"
Header="监控文件"
HeaderIcon="View">
<ToggleSwitch x:Name="TsFilesObserver" />
Expand Down

0 comments on commit 5617ca7

Please sign in to comment.