WIn_RustTools/Editor/EditorWin.xaml
muqing e88ec9db04 重构 EditorTreeView 以使用 Microsoft.UI.Xaml.Controls
在 `EditorTreeView.cs` 中:
- 添加了 `Microsoft.UI.Xaml.Controls`、`RustTools.muqing` 和 `WinUIEditor` 的引用。
- 将 `EditorTreeView` 类从继承 `TreeView` 改为继承 `Microsoft.UI.Xaml.Controls.TreeView`。
- 修改了事件处理程序的绑定方式,去掉了 `this` 关键字。
- 修改了 `TreeView_ItemInvoked`、`TreeView_Expanding` 和 `TreeView_Collapsed` 方法的参数类型,使用了 `Microsoft.UI.Xaml.Controls.TreeView`。
- 在 `TreeView_ItemInvoked` 方法中,添加了处理文件点击事件的逻辑,包括创建 `CodeEditorControl` 实例并将其添加到 `TabViewItem` 中。
- 添加了 `AddTabItem` 事件。

在 `EditorWin.xaml` 中:
- 添加了 `WinUIEditor` 的命名空间引用。
- 在 `Grid` 中添加了 `RowDefinition`,用于定义 `TabView` 的头部和内容区域的高度。
- 注释掉了 `CodeEditorControl` 的 XAML 定义。

在 `EditorWin.xaml.cs` 中:
- 添加了 `Microsoft.UI.Xaml.Media` 和 `WinUIEditor` 的引用。
- 在 `EditorWin` 构造函数中,添加了 `gridedit.SizeChanged` 事件处理程序,用于调整 `TabView` 的高度。
- 添加了 `TreeView_AddTabItem` 方法,用于处理 `AddTabItem` 事件。
- 删除了 `MyTabView_AddTabButtonClick` 方法。

在 `RustTools.csproj` 中:
- 添加了 `WinUIEdit` 包的引用。

重构 EditorTreeView 并添加 WinUI 支持

将 EditorTreeView 类更改为 Microsoft.UI.Xaml.Controls.TreeView,添加相关命名空间引用。更新方法参数类型并处理文件点击事件。调整 EditorWin.xaml 和 EditorWin.xaml.cs 文件,添加事件处理逻辑。移除 MyTabView_AddTabButtonClick 方法,并在 RustTools.csproj 中添加 WinUIEdit 包引用。
2025-01-21 19:26:04 +08:00

124 lines
4.8 KiB
XML

<?xml version="1.0" encoding="utf-8" ?>
<windowex:WindowEx
x:Class="RustTools.Editor.EditorWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WinUIEditor="using:WinUIEditor"
xmlns:controlpages="using:RustTools.Editor"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:editor="using:RustTools.Editor"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:windowex="using:WinUIEx"
MinWidth="500"
MinHeight="500"
mc:Ignorable="d">
<Page Name="page">
<Page.Resources>
<!-- 这是文件夹 -->
<DataTemplate x:Key="FolderTemplate" x:DataType="editor:FileItem">
<TreeViewItem
AutomationProperties.Name="{x:Bind Name}"
IsExpanded="{x:Bind IsExpanded, Mode=TwoWay}"
ItemsSource="{x:Bind Children}">
<StackPanel Orientation="Horizontal">
<FontIcon Glyph="&#xE8B7;" />
<TextBlock Margin="0,0,10,0" />
<TextBlock Text="{x:Bind Name}" />
</StackPanel>
</TreeViewItem>
</DataTemplate>
<!-- 这是文件 -->
<DataTemplate x:Key="FileTemplate">
<TreeViewItem AutomationProperties.Name="{Binding Name}" IsExpanded="False">
<StackPanel Orientation="Horizontal">
<FontIcon Glyph="&#xE8A5;" />
<TextBlock Margin="0,0,10,0" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</TreeViewItem>
</DataTemplate>
<controlpages:ExplorerItemTemplateSelector
x:Key="ExplorerItemTemplateSelector"
FileTemplate="{StaticResource FileTemplate}"
FolderTemplate="{StaticResource FolderTemplate}" />
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid
Grid.Row="0"
Padding="9"
Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
Name="TitleText"
Grid.Column="0"
Margin="16,0,0,0" />
</Grid>
<ScrollViewer
x:Name="scrollview"
Grid.Row="2"
Grid.Column="0"
Width="300"
Margin="0,9,0,6"
Padding="0,0,16,16"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<!--
TreeView 绑定资源和拖放事件
-->
<controlpages:EditorTreeView
x:Name="treeView"
AllowDrop="True"
CanReorderItems="False"
ItemTemplateSelector="{StaticResource ExplorerItemTemplateSelector}"
ItemsSource="{x:Bind DataSource}"
SelectionMode="Single" />
</ScrollViewer>
<controls:PropertySizer
Grid.Row="1"
Grid.Column="1"
Binding="{x:Bind scrollview.Width, Mode=TwoWay}"
Maximum="350"
Minimum="200"
Visibility="Visible" />
<Grid
x:Name="gridedit"
Grid.Row="1"
Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<!-- TabView header height -->
<RowDefinition Height="*" />
<!-- TabView content area height -->
</Grid.RowDefinitions>
<TabView
x:Name="tabview"
IsAddTabButtonVisible="False"
TabCloseRequested="MyTabView_TabCloseRequested" />
<!--<WinUIEditor:CodeEditorControl
x:Name="MyEditor"
HighlightingLanguage="csharp"
DataContextChanged="OnCodeTextChanged" />-->
</Grid>
</Grid>
</Page>
</windowex:WindowEx>