You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
6.6 KiB
129 lines
6.6 KiB
<UserControl xmlns="https://github.com/avaloniaui"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
xmlns:vm="using:MyAvaloniaApp.ViewModels.Pages"
|
|
xmlns:converters="using:MyAvaloniaApp.Converters"
|
|
xmlns:avaloniaEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
|
|
xmlns:attached="using:MyAvaloniaApp.Attached"
|
|
xmlns:heroicons="clr-namespace:HeroIconsAvalonia.Controls;assembly=HeroIconsAvalonia"
|
|
mc:Ignorable="d" d:DesignWidth="1200" d:DesignHeight="800"
|
|
x:Class="MyAvaloniaApp.Views.Pages.EditorPageView"
|
|
x:DataType="vm:EditorPageViewModel">
|
|
|
|
<Design.DataContext>
|
|
<vm:EditorPageViewModel />
|
|
</Design.DataContext>
|
|
|
|
<Grid>
|
|
<Grid.RowDefinitions>
|
|
<RowDefinition Height="Auto"/>
|
|
<RowDefinition Height="*"/>
|
|
</Grid.RowDefinitions>
|
|
|
|
<!-- 页面标题和工具栏 -->
|
|
<Border Grid.Row="0"
|
|
Background="{StaticResource BackgroundLight}"
|
|
BorderBrush="{StaticResource BorderLight}"
|
|
BorderThickness="0,0,0,1"
|
|
Padding="20">
|
|
<StackPanel Spacing="15">
|
|
<!-- 标题 -->
|
|
<TextBlock Text="代码编辑器 - AvaloniaEdit.TextMate"
|
|
FontSize="24"
|
|
FontWeight="Bold"
|
|
Foreground="{StaticResource TextPrimary}"/>
|
|
|
|
<TextBlock Text="基于 AvaloniaEdit 的强大代码编辑器,支持语法高亮、智能提示等功能"
|
|
FontSize="14"
|
|
Foreground="{StaticResource SecondaryGrayDark}"
|
|
Margin="0,5,0,0"/>
|
|
|
|
<!-- 工具栏 -->
|
|
<StackPanel Orientation="Horizontal" Spacing="15" Margin="0,10,0,0">
|
|
<!-- 语言选择 -->
|
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
|
<TextBlock Text="编程语言:"
|
|
FontSize="14"
|
|
FontWeight="SemiBold"
|
|
Foreground="{StaticResource TextPrimary}"
|
|
VerticalAlignment="Center"/>
|
|
<ComboBox ItemsSource="{Binding AvailableLanguages}"
|
|
SelectedItem="{Binding SelectedLanguage}"
|
|
Width="150"
|
|
VerticalAlignment="Center">
|
|
<ComboBox.ItemTemplate>
|
|
<DataTemplate>
|
|
<TextBlock Text="{Binding}"/>
|
|
</DataTemplate>
|
|
</ComboBox.ItemTemplate>
|
|
</ComboBox>
|
|
</StackPanel>
|
|
|
|
<!-- 操作按钮 -->
|
|
<Button Content="清空代码"
|
|
Command="{Binding ClearCodeCommand}"
|
|
HorizontalAlignment="Left"
|
|
VerticalAlignment="Center">
|
|
<Button.Template>
|
|
<ControlTemplate>
|
|
<Border Background="{StaticResource BackgroundWhite}"
|
|
BorderBrush="{StaticResource BorderMedium}"
|
|
BorderThickness="1"
|
|
CornerRadius="6"
|
|
Padding="12,8">
|
|
<ContentPresenter Content="{TemplateBinding Content}"/>
|
|
</Border>
|
|
</ControlTemplate>
|
|
</Button.Template>
|
|
</Button>
|
|
|
|
<Button Content="格式化"
|
|
Command="{Binding FormatCodeCommand}"
|
|
HorizontalAlignment="Left"
|
|
VerticalAlignment="Center">
|
|
<Button.Template>
|
|
<ControlTemplate>
|
|
<Border Background="{StaticResource BackgroundWhite}"
|
|
BorderBrush="{StaticResource BorderMedium}"
|
|
BorderThickness="1"
|
|
CornerRadius="6"
|
|
Padding="12,8">
|
|
<ContentPresenter Content="{TemplateBinding Content}"/>
|
|
</Border>
|
|
</ControlTemplate>
|
|
</Button.Template>
|
|
</Button>
|
|
</StackPanel>
|
|
</StackPanel>
|
|
</Border>
|
|
|
|
<!-- 代码编辑器 -->
|
|
<Grid Grid.Row="1" Margin="5">
|
|
<Border Background="{StaticResource BackgroundWhite}"
|
|
BorderBrush="{StaticResource BorderMedium}"
|
|
BorderThickness="1"
|
|
CornerRadius="8"
|
|
Padding="0">
|
|
<avaloniaEdit:TextEditor x:Name="TextEditor"
|
|
attached:TextEditorAssist.Document="{Binding Document}"
|
|
attached:TextMateHelper.Language="{Binding SelectedLanguage}"
|
|
FontFamily="Consolas, 'Courier New', monospace"
|
|
FontSize="14"
|
|
ShowLineNumbers="True"
|
|
WordWrap="False"
|
|
Margin="10">
|
|
<avaloniaEdit:TextEditor.Styles>
|
|
<Style Selector="avaloniaEdit|TextEditor">
|
|
<Setter Property="Background" Value="{StaticResource BackgroundWhite}"/>
|
|
<Setter Property="Foreground" Value="{StaticResource TextPrimary}"/>
|
|
</Style>
|
|
<Style Selector="avaloniaEdit|TextEditor:focus">
|
|
<Setter Property="Background" Value="{StaticResource BackgroundWhite}"/>
|
|
</Style>
|
|
</avaloniaEdit:TextEditor.Styles>
|
|
</avaloniaEdit:TextEditor>
|
|
</Border>
|
|
</Grid>
|
|
</Grid>
|
|
</UserControl>
|
|
|