/
kochkareal
/
GigaChatLib
Обзор
Документация
Войти
/
kochkareal
/
GigaChatLib
Код
Запросы
0
Задачи
Вики
Пакеты
1
Релизы
0
CI/CD
Аналитика
Безопасность
master
ExampleWPFApp/MainWindow.xaml
491 строка
27 KB
kochkareal
Подготовка GigaChatLib к публикации в виде NuGet-пакета
20 июл 2026, 20:08
20 июл 2026, 20:08
1553b9c
Код
Авторство
О чём код?
<Window x:Class="ExampleWPFApp.MainWindow" 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:ExampleWPFApp" mc:Ignorable="d" Title="GigaChat Client" Height="720" Width="1100" MinHeight="600" MinWidth="900" WindowStartupLocation="CenterScreen" Background="#0F172A" Closed="MainWindow_Closed" > <Window.Resources> <!-- Кисти --> <SolidColorBrush x:Key="PrimaryBrush" Color="#6366F1"/> <SolidColorBrush x:Key="PrimaryDarkBrush" Color="#4F46E5"/> <SolidColorBrush x:Key="SurfaceBrush" Color="#1E293B"/> <SolidColorBrush x:Key="SurfaceLightBrush" Color="#334155"/> <SolidColorBrush x:Key="TextPrimaryBrush" Color="#F8FAFC"/> <SolidColorBrush x:Key="TextSecondaryBrush" Color="#94A3B8"/> <SolidColorBrush x:Key="BorderBrush" Color="#334155"/> <SolidColorBrush x:Key="SuccessBrush" Color="#22C55E"/> <SolidColorBrush x:Key="ErrorBrush" Color="#EF4444"/> <!-- TextBox --> <Style TargetType="TextBox"> <Setter Property="Background" Value="{StaticResource SurfaceBrush}"/> <Setter Property="Foreground" Value="{StaticResource TextPrimaryBrush}"/> <Setter Property="BorderBrush" Value="{StaticResource BorderBrush}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Padding" Value="10,8"/> <Setter Property="CaretBrush" Value="{StaticResource TextPrimaryBrush}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="TextBox"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="6"> <ScrollViewer x:Name="PART_ContentHost" Focusable="False"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- Основная кнопка --> <Style x:Key="PrimaryButton" TargetType="Button"> <Setter Property="Background" Value="{StaticResource PrimaryBrush}"/> <Setter Property="Foreground" Value="White"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Padding" Value="16,10"/> <Setter Property="FontSize" Value="20"/> <Setter Property="FontWeight" Value="SemiBold"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border x:Name="border" Background="{TemplateBinding Background}" CornerRadius="6" Padding="{TemplateBinding Padding}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="{StaticResource PrimaryDarkBrush}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter TargetName="border" Property="Opacity" Value="0.5"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- Кнопка навигации --> <Style x:Key="NavButton" TargetType="RadioButton"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Foreground" Value="{StaticResource TextSecondaryBrush}"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Padding" Value="16,12"/> <Setter Property="FontSize" Value="13"/> <Setter Property="HorizontalContentAlignment" Value="Left"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="RadioButton"> <Border x:Name="border" Background="{TemplateBinding Background}" CornerRadius="6" Padding="{TemplateBinding Padding}"> <ContentPresenter VerticalAlignment="Center"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="{StaticResource SurfaceBrush}"/> <Setter Property="Foreground" Value="{StaticResource TextPrimaryBrush}"/> </Trigger> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="border" Property="Background" Value="{StaticResource SurfaceBrush}"/> <Setter Property="Foreground" Value="{StaticResource TextPrimaryBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- ComboBox --> <Style TargetType="ComboBox"> <Setter Property="Background" Value="White"/> <Setter Property="Foreground" Value="Gray"/> <Setter Property="BorderBrush" Value="{StaticResource BorderBrush}"/> <Setter Property="Padding" Value="10,8"/> </Style> </Window.Resources> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="240"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <!-- Боковая панель --> <Border Grid.Column="0" Background="#1E293B" BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,1,0"> <DockPanel> <!-- Логотип --> <StackPanel DockPanel.Dock="Top" Margin="20,24,20,24"> <TextBlock Text="GigaChat" FontSize="32" FontWeight="Bold" Foreground="{StaticResource TextPrimaryBrush}"/> <TextBlock Text="API Client" FontSize="14" Foreground="{StaticResource TextSecondaryBrush}" Margin="0,2,0,0"/> </StackPanel> <!-- Навигация --> <StackPanel Margin="12,0,12,12"> <RadioButton x:Name="NavChat" Style="{StaticResource NavButton}" Content="💬 Чат" GroupName="Nav" IsChecked="True" Checked="Nav_Checked" FontSize="20"/> <RadioButton x:Name="NavModels" Style="{StaticResource NavButton}" Content="🧠 Модели" GroupName="Nav" Checked="Nav_Checked" FontSize="20"/> <RadioButton x:Name="NavFiles" Style="{StaticResource NavButton}" Content="📁 Файлы" GroupName="Nav" Checked="Nav_Checked" FontSize="20"/> <RadioButton x:Name="NavBalance" Style="{StaticResource NavButton}" Content="💰 Баланс" GroupName="Nav" Checked="Nav_Checked" FontSize="20"/> <Separator Margin="8,12" Background="{StaticResource BorderBrush}"/> <RadioButton x:Name="NavSettings" Style="{StaticResource NavButton}" Content="⚙ Настройки" GroupName="Nav" Checked="Nav_Checked" FontSize="20"/> <!-- Статус --> <Border DockPanel.Dock="Bottom" Padding="20,12" BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,1,0,0"> <StackPanel> <TextBlock x:Name="StatusText" Text="○ Не подключено" FontSize="14" Foreground="{StaticResource TextSecondaryBrush}"/> <TextBlock x:Name="ModelText" Text="Модель: —" FontSize="14" Foreground="{StaticResource TextSecondaryBrush}" Margin="0,4,0,0"/> </StackPanel> </Border> </StackPanel> </DockPanel> </Border> <!-- Контент --> <Grid Grid.Column="2"> <!-- Экран настроек --> <Grid x:Name="SettingsView" Visibility="Visible"> <ScrollViewer VerticalScrollBarVisibility="Auto"> <StackPanel MaxWidth="600" Margin="32,32,32,32"> <TextBlock Text="Настройки подключения" FontSize="28" FontWeight="SemiBold" Foreground="{StaticResource TextPrimaryBrush}" Margin="0,0,0,24"/> <Border Background="{StaticResource SurfaceBrush}" CornerRadius="12" Padding="24"> <StackPanel> <TextBlock Text="Authorization Key (Base64)" Foreground="{StaticResource TextSecondaryBrush}" FontSize="14" Margin="0,0,0,8"/> <TextBox x:Name="AuthKeyBox" FontSize="13"/> <TextBlock Text="Область доступа (Scope)" Foreground="{StaticResource TextSecondaryBrush}" FontSize="14" Margin="0,20,0,8"/> <ComboBox x:Name="ScopeBox" FontSize="14" SelectedIndex="0" > <ComboBoxItem Content="GIGACHAT_API_PERS (физлица)"/> <ComboBoxItem Content="GIGACHAT_API_B2B (юрлица, пакеты)"/> <ComboBoxItem Content="GIGACHAT_API_CORP (юрлица, pay-as-you-go)"/> </ComboBox> <CheckBox x:Name="IgnoreCertErrorsBox" Content="Игнорировать ошибки TLS-сертификата (только для отладки)" Foreground="{StaticResource TextSecondaryBrush}" FontSize="13" IsChecked="False" Margin="0,20,0,0"/> <Button Style="{StaticResource PrimaryButton}" Content="Подключиться" Margin="0,24,0,0" HorizontalAlignment="Left" Click="Connect_Click" FontSize="20"/> <TextBlock x:Name="StatusMessage" Foreground="{StaticResource TextSecondaryBrush}" FontSize="13" Margin="0,16,0,0" TextWrapping="Wrap"/> </StackPanel> </Border> </StackPanel> </ScrollViewer> </Grid> <!-- Экран чата --> <Grid x:Name="ChatView" Visibility="Collapsed" Margin="24"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <DockPanel Grid.Row="0" Margin="0,0,0,16"> <TextBlock Text="Диалог" FontSize="22" FontWeight="SemiBold" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center"/> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center"> <ComboBox x:Name="ModelSelector" Width="200" Margin="0,0,8,0"/> <Button Style="{StaticResource PrimaryButton}" Content="Очистить" Padding="12,8" Click="ClearChat_Click"/> </StackPanel> </DockPanel> <Border Grid.Row="1" Background="{StaticResource SurfaceBrush}" CornerRadius="12" Padding="8"> <ScrollViewer x:Name="ChatScroller" VerticalScrollBarVisibility="Auto"> <ItemsControl x:Name="MessagesList"> <ItemsControl.ItemTemplate> <DataTemplate> <Border Margin="4" Padding="14,10" CornerRadius="12" MaxWidth="600" HorizontalAlignment="{Binding Alignment}" Background="{Binding Background}"> <TextBlock Text="{Binding Content}" Foreground="{StaticResource TextPrimaryBrush}" TextWrapping="Wrap" FontSize="13.5"/> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> </Border> <Grid Grid.Row="2" Margin="0,12,0,0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBox x:Name="InputBox" FontSize="14" KeyDown="InputBox_KeyDown"/> <Button Grid.Column="1" Style="{StaticResource PrimaryButton}" Content="➤" FontSize="16" Margin="8,0,0,0" Padding="14,8" Click="Send_Click"/> </Grid> </Grid> <!-- Экран моделей --> <Grid x:Name="ModelsView" Visibility="Collapsed" Margin="24"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <DockPanel Grid.Row="0" Margin="0,0,0,16"> <TextBlock Text="Доступные модели" FontSize="22" FontWeight="SemiBold" Foreground="{StaticResource TextPrimaryBrush}"/> <Button Style="{StaticResource PrimaryButton}" Content="Обновить" HorizontalAlignment="Right" Padding="12,8" Click="RefreshModels_Click"/> </DockPanel> <Border Grid.Row="1" Background="{StaticResource SurfaceBrush}" CornerRadius="12"> <ListView x:Name="ModelsList" Background="Transparent" BorderThickness="0"> <ListView.ItemTemplate> <DataTemplate> <Border Padding="16,12" BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,0,1"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Id}" Foreground="{StaticResource TextPrimaryBrush}" FontSize="13.5" FontWeight="SemiBold"/> <TextBlock Grid.Column="1" Text="{Binding Type}" Foreground="{StaticResource TextSecondaryBrush}" FontSize="12" Margin="12,0"/> <TextBlock Grid.Column="2" Text="{Binding OwnedBy}" Foreground="{StaticResource TextSecondaryBrush}" FontSize="12"/> </Grid> </Border> </DataTemplate> </ListView.ItemTemplate> </ListView> </Border> </Grid> <!-- Экран файлов --> <Grid x:Name="FilesView" Visibility="Collapsed" Margin="24"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <DockPanel Grid.Row="0" Margin="0,0,0,16"> <TextBlock Text="Хранилище файлов" FontSize="22" FontWeight="SemiBold" Foreground="{StaticResource TextPrimaryBrush}"/> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <Button Style="{StaticResource PrimaryButton}" Content="Загрузить" Padding="12,8" Margin="0,0,8,0" Click="UploadFile_Click"/> <Button Style="{StaticResource PrimaryButton}" Content="Обновить" Padding="12,8" Click="RefreshFiles_Click"/> </StackPanel> </DockPanel> <Border Grid.Row="1" Background="{StaticResource SurfaceBrush}" CornerRadius="12"> <ListView x:Name="FilesList" Background="Transparent" BorderThickness="0"> <ListView.ItemTemplate> <DataTemplate> <Border Padding="16,12" BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,0,1"> <DockPanel> <Button DockPanel.Dock="Right" Content="✕" Style="{StaticResource PrimaryButton}" Padding="8,4" FontSize="11" Click="DeleteFile_Click" Tag="{Binding Id}"/> <StackPanel> <TextBlock Text="{Binding Filename}" Foreground="{StaticResource TextPrimaryBrush}" FontSize="13.5" FontWeight="SemiBold"/> <StackPanel Orientation="Horizontal" Margin="0,4,0,0"> <TextBlock Text="{Binding Bytes, StringFormat={}{0} байт}" Foreground="{StaticResource TextSecondaryBrush}" FontSize="11.5"/> <TextBlock Text=" • " Foreground="{StaticResource TextSecondaryBrush}" FontSize="11.5"/> <TextBlock Text="{Binding Id}" Foreground="{StaticResource TextSecondaryBrush}" FontSize="11.5"/> </StackPanel> </StackPanel> </DockPanel> </Border> </DataTemplate> </ListView.ItemTemplate> </ListView> </Border> </Grid> <!-- Экран баланса --> <Grid x:Name="BalanceView" Visibility="Collapsed" Margin="24"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <DockPanel Grid.Row="0" Margin="0,0,0,16"> <TextBlock Text="Баланс токенов" FontSize="22" FontWeight="SemiBold" Foreground="{StaticResource TextPrimaryBrush}"/> <Button Style="{StaticResource PrimaryButton}" Content="Обновить" HorizontalAlignment="Right" Padding="12,8" Click="RefreshBalance_Click"/> </DockPanel> <Border Grid.Row="1" Background="{StaticResource SurfaceBrush}" CornerRadius="12" Padding="24"> <StackPanel> <ItemsControl x:Name="BalanceList"> <ItemsControl.ItemTemplate> <DataTemplate> <Border Padding="16,12" Margin="0,0,0,8" Background="{StaticResource SurfaceLightBrush}" CornerRadius="8"> <DockPanel> <TextBlock DockPanel.Dock="Left" Text="{Binding Usage}" Foreground="{StaticResource TextPrimaryBrush}" FontSize="14" FontWeight="SemiBold"/> <TextBlock DockPanel.Dock="Right" Text="{Binding Value, StringFormat={}{0:N0}}" Foreground="{StaticResource PrimaryBrush}" FontSize="16" FontWeight="Bold" HorizontalAlignment="Right"/> </DockPanel> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <TextBlock x:Name="BalanceInfo" Foreground="{StaticResource TextSecondaryBrush}" FontSize="12" Margin="0,16,0,0" TextWrapping="Wrap"/> </StackPanel> </Border> </Grid> </Grid> </Grid> </Window>