﻿<Window x:Class="OpenTapEditor.VariableSelector"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        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:local="clr-namespace:OpenTapEditor"
        mc:Ignorable="d"
        xmlns:ui="clr-namespace:UILib;assembly=UILib"
        WindowStartupLocation="CenterOwner"
        Closing="Window_Closing"
        Title="选择变量" Height="800" Width="600">
    <Window.Resources>
        <!-- 保持选中背景色的 TextBox 样式 -->
        <Style x:Key="KeepSelectionTextBoxStyle" TargetType="TextBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Border x:Name="Bd"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                            <ScrollViewer x:Name="PART_ContentHost" 
                                      Focusable="False"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <!-- 聚焦时 -->
                            <Trigger Property="IsFocused" Value="True">
                                <Setter TargetName="Bd" 
                                    Property="BorderBrush" 
                                    Value="{StaticResource PrimaryBrush}"/>
                            </Trigger>

                            <!-- ✅ 关键：非聚焦时的选中样式 -->
                            <Trigger Property="IsFocused" Value="False">
                                <Setter Property="SelectionBrush" Value="#FF007ACC"/>
                                <Setter Property="SelectionOpacity" Value="0.6"/>
                                <Setter Property="CaretBrush" Value="Transparent"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="6*"/>
            <RowDefinition Height="4*"/>
        </Grid.RowDefinitions>

        <local:VariableReadOnlyTree x:Name="tree" Datasource="{Binding Variables}">

        </local:VariableReadOnlyTree>

        <GroupBox Grid.Row="1" Header="结果">
            <TextBox TextWrapping="Wrap" VerticalContentAlignment="Top" x:Name="tb"
                     Text="{Binding Result,UpdateSourceTrigger=PropertyChanged}" />
            <!--<RichTextBox Focusable="False">
                <FlowDocument>
                    <Paragraph>
                        <Run x:Name="tb" Text="{Binding Result,UpdateSourceTrigger=PropertyChanged}" />
                    </Paragraph>
                </FlowDocument>
            </RichTextBox>-->
        </GroupBox>
    </Grid>
</Window>
