dockpane.xaml初步设计、cs加入了sendonclick和newmessage,不太可信
This commit is contained in:
parent
51b1cc1b7d
commit
322437a00f
@ -590,7 +590,7 @@ public class Gateway
|
||||
return JsonConvert.SerializeObject(paramSchema, settings);;
|
||||
}
|
||||
|
||||
public static async void TestChatMessage(string message, string model, string gdbPath,//message,qwen-max,传个空字符串,传一个方法(回调,用来调用方法)1
|
||||
public static async void TestChatMessage(string message, string model, string gdbPath,//生成并返回一个聊天消息(ChatMessageItem),模拟AI助手的响应。通过回调函数 callback 将消息传递到前端显示。1
|
||||
Action<MessageListItem> callback)
|
||||
{
|
||||
MessageListItem chatListItem = new ChatMessageItem//返回的东西1
|
||||
|
||||
@ -16,13 +16,40 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
|
||||
<Grid Margin="10" Background="White">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="4*"/>
|
||||
<RowDefinition Height="10"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<DockPanel Grid.Row="0" LastChildFill="true" KeyboardNavigation.TabNavigation="Local" Height="30">
|
||||
<Button Content="Test Server" Name="TestServer" Click="TestServer_OnClick"></Button>
|
||||
|
||||
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" Name="MessageScrollViewer">
|
||||
|
||||
</ScrollViewer>
|
||||
|
||||
<DockPanel Grid.Row="2" Background="AliceBlue" Margin="0,0,0,0">
|
||||
<Button
|
||||
x:Name="SendButton"
|
||||
Content="发送"
|
||||
Width="45"
|
||||
Height="40"
|
||||
Margin="5,0,5,0"
|
||||
Background="#FFD0E0F0"
|
||||
BorderBrush="#FFA0B0C0"
|
||||
BorderThickness="1"
|
||||
Padding="0"
|
||||
DockPanel.Dock="Right"
|
||||
Click="Send_0nclick"/>
|
||||
|
||||
<TextBox x:Name="InputTextBox"
|
||||
Height="40"
|
||||
Margin="5,0,5,0"
|
||||
TextWrapping="Wrap"
|
||||
Background="White"
|
||||
BorderBrush="#FFD0D0D0"
|
||||
BorderThickness="1"
|
||||
Padding="5"/>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -1,36 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Windows.Documents;
|
||||
using ArcGIS.Desktop.Core.Geoprocessing;
|
||||
using LinkToolAddin.client;
|
||||
using LinkToolAddin.host;
|
||||
using LinkToolAddin.host.llm;
|
||||
using LinkToolAddin.host.llm.entity;
|
||||
using LinkToolAddin.message;
|
||||
using LinkToolAddin.resource;
|
||||
using LinkToolAddin.server;
|
||||
using log4net;
|
||||
using log4net.Appender;
|
||||
using log4net.Config;
|
||||
using log4net.Layout;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ModelContextProtocol.Client;
|
||||
using ModelContextProtocol.Protocol.Types;
|
||||
using ModelContextProtocol.Server;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace LinkToolAddin.ui.dockpane
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DialogDockpaneView.xaml
|
||||
/// 显示消息列表、输入框和发送按钮
|
||||
/// </summary>
|
||||
public partial class DialogDockpaneView : UserControl
|
||||
{
|
||||
@ -81,5 +86,69 @@ namespace LinkToolAddin.ui.dockpane
|
||||
log.Info("Info 日志(控制台和文件可见)");
|
||||
log.Error("Error 日志(严重问题)");
|
||||
}
|
||||
|
||||
private void Send_0nclick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string userInput = InputTextBox.Text.Trim();
|
||||
if (string.IsNullOrEmpty(userInput)) return;
|
||||
var userMessage = new ChatMessageItem
|
||||
{
|
||||
id = Guid.NewGuid().ToString(),
|
||||
role = "user",
|
||||
content = userInput,
|
||||
type = MessageType.CHAT_MESSAGE
|
||||
};
|
||||
// 使用统一方法显示消息
|
||||
NewMessage(userMessage);
|
||||
|
||||
// 清空输入框
|
||||
InputTextBox.Clear();
|
||||
|
||||
Gateway.SendMessageStream(InputTextBox.Text, model: "qwen-max", gdbPath: "c: /user.gdb", NewMessage);
|
||||
}
|
||||
|
||||
public void NewMessage(MessageListItem messagelistItem)
|
||||
{
|
||||
// 创建用于显示消息内容的 TextBlock
|
||||
TextBlock textBlock = new TextBlock();
|
||||
textBlock.Text = InputTextBox.Text;
|
||||
textBlock.TextWrapping = TextWrapping.Wrap; // 自动换行
|
||||
textBlock.VerticalAlignment = VerticalAlignment.Center;
|
||||
|
||||
// 创建 Border 作为消息气泡容器
|
||||
Border border = new Border();
|
||||
border.Child = textBlock;
|
||||
border.CornerRadius = new CornerRadius(10);
|
||||
border.Padding = new Thickness(10);
|
||||
border.Margin = new Thickness(5);
|
||||
|
||||
// 设置默认宽度限制
|
||||
border.MaxWidth = 300;
|
||||
|
||||
if (messagelistItem.role == "user")
|
||||
{
|
||||
// 浅蓝色背景,靠右
|
||||
border.Background = new SolidColorBrush(Color.FromRgb(212, 229, 239)); // 浅蓝
|
||||
border.HorizontalAlignment = HorizontalAlignment.Right;
|
||||
}
|
||||
else if (messagelistItem.role == "assistant")
|
||||
{
|
||||
// 浅灰背景,靠左
|
||||
border.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240)); // 浅灰
|
||||
border.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
|
||||
if (messagelistItem.type == MessageType.TOOL_MESSAGE)
|
||||
{
|
||||
border.BorderBrush = new SolidColorBrush(Color.FromRgb(212, 220, 223)); // 灰蓝色边框
|
||||
border.BorderThickness = new Thickness(1);
|
||||
}
|
||||
}
|
||||
// 把气泡添加到 MessageListView 显示
|
||||
MessageListView.Items.Add(border);
|
||||
|
||||
// 自动滚动到底部
|
||||
MessageScrollViewer.ScrollToEnd();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Console;
|
||||
using System.Collections.ObjectModel;
|
||||
using LinkToolAddin.message;
|
||||
|
||||
namespace LinkToolAddin.ui.dockpane
|
||||
{
|
||||
@ -28,12 +30,17 @@ namespace LinkToolAddin.ui.dockpane
|
||||
{
|
||||
private const string _dockPaneID = "DialogDockpane";
|
||||
|
||||
private ObservableCollection<MessageListItem> _message = new ObservableCollection<MessageListItem>();
|
||||
//ObservableCollection<T> 是 .NET 提供的一个特殊集合类,它会在集合发生变化时自动通知 UI 更新,它实现了 INotifyCollectionChanged 接口,UI 绑定后可以自动刷新。
|
||||
public ObservableCollection<MessageListItem> Messages => _message;
|
||||
//定义了一个只读属性 Messages,返回内部的 _messages 集合。
|
||||
//该属性将被绑定到 UI 的 ItemsControl.ItemsSource 上,这样 UI 就能实时显示新消息。
|
||||
protected DialogDockpaneViewModel() { }
|
||||
|
||||
/// <summary>
|
||||
/// Show the DockPane.
|
||||
/// </summary>
|
||||
internal static void Show()
|
||||
internal static void Show()//显示面板
|
||||
{
|
||||
DockPane pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
|
||||
if (pane == null)
|
||||
@ -45,18 +52,18 @@ namespace LinkToolAddin.ui.dockpane
|
||||
/// <summary>
|
||||
/// Text shown near the top of the DockPane.
|
||||
/// </summary>
|
||||
private string _heading = "My DockPane";
|
||||
private string _heading = "My DockPane";//标题栏文字
|
||||
public string Heading
|
||||
{
|
||||
get => _heading;
|
||||
set => SetProperty(ref _heading, value);
|
||||
get => _heading;//绑定到 UI 上的标题文字,默认是 "My DockPane"。
|
||||
set => SetProperty(ref _heading, value);//属性变更通知方法,用于支持数据绑定
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button implementation to show the DockPane.
|
||||
/// </summary>
|
||||
internal class DialogDockpane_ShowButton : Button
|
||||
internal class DialogDockpane_ShowButton : Button//用于打开面板
|
||||
{
|
||||
protected override void OnClick()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user