添加项目文件。
This commit is contained in:
208
WPFUI.Test/ChatFunction/ChatDialogue.xaml
Normal file
208
WPFUI.Test/ChatFunction/ChatDialogue.xaml
Normal file
@@ -0,0 +1,208 @@
|
||||
<UserControl x:Class="WPFUI.Test.ChatDialogue"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:AduSkin="https://github.com/aduskin"
|
||||
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WPFUI.Test"
|
||||
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
|
||||
xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:providers="clr-namespace:LangChain.Providers;assembly=LangChain.Providers.Abstractions"
|
||||
Width="800"
|
||||
Height="450"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=local:ChatDialogueViewModel}">
|
||||
<!-- xmlns:md="clr-namespace:EleCho.MdViewer;assembly=EleCho.MdViewer"
|
||||
xmlns:mu="clr-namespace:EleCho.MdViewer.Markup;assembly=EleCho.MdViewer" -->
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<!-- <ResourceDictionary Source="/MarkdownStyleRes.xaml" /> -->
|
||||
<!-- <mu:ControlsDictionary />
|
||||
<mu:ThemeDictionary ColorMode="Dark" /> -->
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<DrawingImage x:Key="deepseek">
|
||||
<DrawingImage.Drawing>
|
||||
<DrawingGroup ClipGeometry="M0,0 V1024 H1024 V0 H0 Z">
|
||||
<GeometryDrawing Brush="#FF4D6BFE" Geometry="F1 M1024,1024z M0,0z M979.968,219.0336C969.8816,214.016 965.376,223.5392 959.3856,228.352 957.44,230.0416 955.5968,231.936 953.9072,233.8304 939.0592,249.856 921.856,260.1472 899.1232,258.9184 866.2016,257.024 837.9904,267.52 813.1072,292.864 807.8848,261.5808 790.1696,242.944 763.4432,230.9632 749.312,224.768 735.232,218.5216 725.4528,204.9024 718.4896,195.3792 716.5952,184.6272 713.216,174.08 711.1168,167.6288 708.9664,161.1776 701.5424,160 693.6576,158.8224 690.5344,165.4784 687.4112,171.008 675.0208,193.6896 670.208,219.0336 670.5152,244.3776 671.6416,301.4656 695.808,347.0848 743.8336,379.5968 749.312,383.4368 750.7456,387.0208 749.1072,392.4992 745.728,403.7632 741.9392,414.5152 738.56,425.728 736.4096,432.896 733.0816,434.5856 725.4016,431.4624A217.344,217.344,0,0,1,656.128,384.3584C621.9776,351.3856,591.104,314.8288,552.704,286.4128A511.0784,511.0784,0,0,0,525.1584,267.52C485.9904,229.2736 530.432,197.9904 540.7232,194.1504 551.4752,190.3616 544.512,176.9472 509.6448,177.2032 474.9824,177.2032 443.1872,188.928 402.5856,204.4416 396.5952,206.848 390.4,208.5376 384.1536,209.92A385.9968,385.9968,0,0,0,269.2608,205.8752C194.2016,214.2208 134.2464,249.856 90.0608,310.528 37.1712,383.488 24.4736,466.3296 39.7824,552.8576 55.808,643.8912 102.144,719.4112 173.6192,778.1888 247.5008,839.3728 332.8,869.2736 430.08,863.5392 489.1136,860.16 554.8032,852.2752 628.8896,789.4528 647.5264,798.7712 667.136,802.3552 699.8528,805.2224 724.9408,807.5776 749.1072,803.9936 767.744,800.2048 797.1328,793.9584 794.9824,766.976 784.4352,761.7024 698.6752,721.7664 717.568,738.048 700.3136,724.8896 744.0896,673.28 809.7792,619.52 835.328,445.5424 837.2736,431.7184 835.584,423.1168 835.328,411.8528 835.328,405.1968 836.7616,402.3296 844.4416,401.6128 865.9456,399.4624 886.9376,393.0112 906.0864,382.6688 961.792,352.3584 984.0128,302.4384 989.4912,242.432 990.208,233.3696 989.4912,223.7952 979.712,219.0336L979.9168,219.0336z M495.2576,757.9136C412.1088,692.3776 371.712,670.8736 354.9696,671.8976 339.456,672.8192 342.0672,690.4832 345.6512,702.208 349.2352,713.6768 354.048,721.5616 360.4992,731.5968 365.0048,738.2528 368.128,748.3392 355.8912,755.7632 329.1648,772.4544 282.5728,750.2336 280.4224,749.056 226.1504,717.0048 180.7872,674.9696 148.992,617.1136A401.7152,401.7152,0,0,1,97.3824,438.4256C96.6656,422.8608,101.1712,417.5872,116.2752,414.72A193.024,193.024,0,0,1,177.2032,413.0816C262.0416,425.472 334.3872,463.4624 394.9056,523.6736 429.5168,558.1312 455.5776,598.9376 482.6112,639.1296 511.2832,681.6256 542.1056,722.0736 581.2736,755.2512 595.0976,766.976 606.1568,775.8336 616.6016,782.2848 584.6016,785.8688 531.3536,786.5856 495.0016,757.6576L495.2576,757.9136z M535.1936,500.992A12.288,12.288,0,0,1,547.328,488.8064C554.0352,488.8064,559.5136,494.336,559.5136,500.992A12.288,12.288,0,0,1,547.1232,513.1776A12.032,12.032,0,0,1,534.9376,501.248L534.9376,500.992 535.1424,500.992z M658.944,564.7872A79.872,79.872,0,0,1,635.5456,571.2384A51.8656,51.8656,0,0,1,603.7504,561.2032C592.9984,552.1408,585.1136,546.8672,581.7344,530.8928A64.1024,64.1024,0,0,1,582.4512,507.4432C585.3184,494.336 582.2464,486.1952 572.928,478.5152 565.504,472.3712 555.9296,470.6304 545.4336,470.6304A18.432,18.432,0,0,1,535.3984,467.5584A10.24,10.24,0,0,1,530.0224,461.4144C529.5616,460.032,529.4592,458.5984,529.5616,457.216A10.3424,10.3424,0,0,1,530.8416,453.2224C532.0704,451.072 537.2928,445.7984 538.5216,444.8256 552.6016,436.736 569.088,439.3472 584.1408,445.5424 598.2208,451.2768 608.7168,461.824 624.0768,476.6208 639.5904,494.5408 642.4576,499.5584 651.3152,513.1776 658.2272,523.7248 664.6784,534.6816 668.9792,547.1232 671.5904,554.8032 668.2624,561.2032 658.944,565.0432L658.944,564.7872z" />
|
||||
</DrawingGroup>
|
||||
</DrawingImage.Drawing>
|
||||
</DrawingImage>
|
||||
<local:RoleToDisplayConverter x:Key="RoleToDisplayConverter" />
|
||||
|
||||
<!-- 定义包含 DataTrigger 的 DataTemplate -->
|
||||
<DataTemplate x:Key="DynamicTemplate" DataType="{x:Type providers:Message}">
|
||||
<ContentControl x:Name="ContentControl" Content="{Binding}" />
|
||||
<DataTemplate.Triggers>
|
||||
<!-- 当 Role 为 Admin 时,使用 Admin 的模板 -->
|
||||
<DataTrigger Value="{x:Static providers:MessageRole.Ai}" Binding="{Binding Role}">
|
||||
<Setter TargetName="ContentControl" Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<material:Card Margin="5"
|
||||
HorizontalAlignment="{Binding Path=DataContext.Role,
|
||||
RelativeSource={RelativeSource Mode=Self},
|
||||
Converter={StaticResource RoleToDisplayConverter}}"
|
||||
Background="{Binding Path=DataContext.Role,
|
||||
Mode=OneTime,
|
||||
RelativeSource={RelativeSource Mode=Self},
|
||||
Converter={StaticResource RoleToDisplayConverter}}">
|
||||
<StackPanel Margin="5" Orientation="Horizontal">
|
||||
<Image Width="32"
|
||||
Height="32"
|
||||
Source="{StaticResource deepseek}"
|
||||
Visibility="{Binding Path=DataContext.Role,
|
||||
RelativeSource={RelativeSource Mode=Self},
|
||||
Converter={StaticResource RoleToDisplayConverter}}" />
|
||||
<!-- <md:MarkdownViewer x:Name="Viewer" Content="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> -->
|
||||
<markdig:MarkdownViewer x:Name="Viewer"
|
||||
Markdown="{Binding Content,
|
||||
Mode=TwoWay,
|
||||
UpdateSourceTrigger=PropertyChanged}"
|
||||
Pipeline="{Binding DataContext.Pipeline,
|
||||
Mode=TwoWay,
|
||||
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
|
||||
</StackPanel>
|
||||
<!-- <mdxam:MarkdownScrollViewer HorizontalAlignment="Right" Markdown="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalScrollBarVisibility="Auto" /> -->
|
||||
</material:Card>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
|
||||
<!-- 当 Role 为 User 时,使用 User 的模板 -->
|
||||
<DataTrigger Value="{x:Static providers:MessageRole.Human}" Binding="{Binding Role}">
|
||||
<Setter TargetName="ContentControl" Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<material:Card Margin="5"
|
||||
HorizontalAlignment="{Binding Path=DataContext.Role,
|
||||
RelativeSource={RelativeSource Mode=Self},
|
||||
Converter={StaticResource RoleToDisplayConverter}}"
|
||||
Background="{Binding Path=DataContext.Role,
|
||||
Mode=OneTime,
|
||||
RelativeSource={RelativeSource Mode=Self},
|
||||
Converter={StaticResource RoleToDisplayConverter}}">
|
||||
<TextBox MaxWidth="300"
|
||||
VerticalAlignment="Center"
|
||||
Background="Transparent"
|
||||
BorderBrush="{Binding Path=DataContext.Role,
|
||||
Mode=OneTime,
|
||||
RelativeSource={RelativeSource Mode=Self},
|
||||
Converter={StaticResource RoleToDisplayConverter}}"
|
||||
BorderThickness="0"
|
||||
FontSize="12"
|
||||
IsReadOnly="True"
|
||||
Style="{x:Null}"
|
||||
Text="{Binding Content}"
|
||||
TextWrapping="WrapWithOverflow" />
|
||||
</material:Card>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<FrameworkElement.CommandBindings>
|
||||
<CommandBinding Command="{x:Static markdig:Commands.Hyperlink}" Executed="OpenHyperlink" />
|
||||
<CommandBinding Command="{x:Static markdig:Commands.Image}" Executed="ClickOnImage" />
|
||||
</FrameworkElement.CommandBindings>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<!-- <Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions> -->
|
||||
<ScrollViewer x:Name="ChatText"
|
||||
Grid.Row="0"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<ItemsControl d:ItemsSource="{d:SampleData ItemCount=5}"
|
||||
ItemsSource="{Binding ChatHistory,
|
||||
Mode=TwoWay,
|
||||
UpdateSourceTrigger=PropertyChanged}"
|
||||
ItemTemplate="{StaticResource DynamicTemplate}">
|
||||
<!-- <ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border
|
||||
Margin="5"
|
||||
HorizontalAlignment="{Binding Path=DataContext.Role, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource RoleToDisplayConverter}}"
|
||||
Background="{Binding Path=DataContext.Role, Mode=OneTime, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource RoleToDisplayConverter}}"
|
||||
CornerRadius="10">
|
||||
<StackPanel HorizontalAlignment="{Binding Path=DataContext.Role, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource RoleToDisplayConverter}}" Orientation="Horizontal">
|
||||
<Image
|
||||
Width="32"
|
||||
Height="32"
|
||||
Source="{StaticResource deepseek}"
|
||||
Visibility="{Binding Path=DataContext.Role, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource RoleToDisplayConverter}}" />
|
||||
<markdig:MarkdownViewer x:Name="Viewer" HorizontalAlignment="{Binding Path=DataContext.Role, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource RoleToDisplayConverter}}" Markdown="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</StackPanel>
|
||||
-->
|
||||
<!-- <mdxam:MarkdownScrollViewer HorizontalAlignment="Right" Markdown="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalScrollBarVisibility="Auto" /> -->
|
||||
<!-- </Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate> -->
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
|
||||
<Border Grid.Row="1"
|
||||
Background="Gray"
|
||||
CornerRadius="5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column="0"
|
||||
Margin="5"
|
||||
Text="{Binding UserInput, UpdateSourceTrigger=PropertyChanged}">
|
||||
<b:Interaction.Triggers>
|
||||
<b:KeyTrigger Key="Enter">
|
||||
<b:InvokeCommandAction Command="{Binding SendCommand}" CommandParameter="{Binding ElementName=ChatText}" />
|
||||
</b:KeyTrigger>
|
||||
</b:Interaction.Triggers>
|
||||
</TextBox>
|
||||
<!-- <Button x:Name="button1" Click="button1_Click" Content="单轮流式聊天" />
|
||||
<Button x:Name="button2" Click="button2_Click" Content="单轮普通聊天" />
|
||||
<Button x:Name="button3" Click="button3_Click" Content="多轮流式对话" />
|
||||
<Button x:Name="button4" Click="button4_Click" Content="多轮普通聊天" /> -->
|
||||
<Button Grid.Column="1"
|
||||
Margin="5"
|
||||
Command="{Binding SendCommand}"
|
||||
CommandParameter="{Binding ElementName=ChatText}"
|
||||
ToolTip="发送">
|
||||
<material:PackIcon Kind="Send" />
|
||||
</Button>
|
||||
<Button Grid.Column="2"
|
||||
Margin="5"
|
||||
Command="{Binding SendCancelCommand}"
|
||||
CommandParameter="{Binding ElementName=ChatText}"
|
||||
ToolTip="发送">
|
||||
<material:PackIcon Kind="Stop" />
|
||||
</Button>
|
||||
<Button Grid.Column="3"
|
||||
Margin="5"
|
||||
Command="{Binding NewSessionCommand}"
|
||||
ToolTip="新对话">
|
||||
<material:PackIcon Kind="Dialogue" />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
<!-- <GroupBox Width="100" Header="分类" />
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="A1" />
|
||||
<TextBlock Text="A23" />
|
||||
<Button Content="Button" />
|
||||
<Button Content="Button" />
|
||||
<Button Content="Button" />
|
||||
</StackPanel> -->
|
||||
</Grid>
|
||||
</UserControl>
|
||||
Reference in New Issue
Block a user