Эх сурвалжийг харах

Работа с изображениями

fly9024 10 сар өмнө
parent
commit
b961bb7928

BIN
AvaloniaApplication5/Assets/female.png


BIN
AvaloniaApplication5/Assets/logo.png


BIN
AvaloniaApplication5/Assets/male.png


+ 6 - 0
AvaloniaApplication5/AvaloniaApplication5.csproj

@@ -13,6 +13,12 @@
     <AvaloniaResource Include="Assets\**" />
   </ItemGroup>
 
+  <ItemGroup>
+    <None Remove="Assets\female.png" />
+    <None Remove="Assets\logo.png" />
+    <None Remove="Assets\male.png" />
+  </ItemGroup>
+
 
   <ItemGroup>
     <PackageReference Include="Avalonia" Version="11.0.2" />

+ 8 - 0
AvaloniaApplication5/ViewModels/PageUserCabinetViewModel.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Generic;
+using Avalonia.Media.Imaging; //äëÿ çàãðóçêè èçîáðàæåíèé. Äëÿ Bitmap ïî óìîë÷àíèþ ïîäêëþ÷àåòñÿ System.Draving, ýòî êîñÿê. Íå ïåðåïóòàéòå
 using System.Linq;
+using Avalonia.Platform;
 using AvaloniaApplication5.Models;
 using Microsoft.EntityFrameworkCore;
 using ReactiveUI;
@@ -35,6 +37,12 @@ namespace AvaloniaApplication5.ViewModels
         public bool ChangePass { get => changePass; set =>this.RaiseAndSetIfChanged(ref changePass, value); }
         public string PasswordMatch { get => passwordMatch; set => passwordMatch = value; }
         public string Message { get => message; set =>this.RaiseAndSetIfChanged(ref message,value); }
+       //ïîëó÷àåì ïóòü ê êàðòèíêå â çàâèñèìîñòè îò ïîëà
+        public string Imagepath => CurrentUser.User.IdGender == 3 ? "avares://AvaloniaApplication5/Assets/male.png" : "avares://AvaloniaApplication5/Assets/female.png";
+        //ñâîéñâî äëÿ ïðèâÿçêè ê image íà ñòðàíèöå
+        public Bitmap? ImageBind => new Bitmap(AssetLoader.Open(new Uri(Imagepath)));
+
+       
 
         bool changePass = false;
 

+ 1 - 0
AvaloniaApplication5/Views/PageLogin.axaml

@@ -18,5 +18,6 @@
 		<TextBox PasswordChar="•" Text="{Binding PageLoginVM.Password}"/>
 		<Button Content="Войти" Command="{Binding LoadPageList}" IsDefault="True"/>
 		<TextBlock Classes="ErrorMessage" Text="{Binding PageLoginVM.Message}"/>
+		<Image Source="/Assets/logo.png" Width="300" Height="300"/>
 	</StackPanel>
 </UserControl>

+ 3 - 0
AvaloniaApplication5/Views/PageUserCabinet.axaml

@@ -7,6 +7,9 @@
              x:DataType="vm:MainWindowViewModel"
 			 x:Class="AvaloniaApplication5.Views.PageUserCabinet">
 	<StackPanel>
+		<Image Width="100" Height="100" Source="{Binding PageUCabinetVM.ImageBind}"/>
+		
+		<TextBlock Text="{Binding PageUCabinetVM.Imagepath}"/>
 		<TextBlock Text="Имя"/>
 		<TextBox Text="{Binding PageUCabinetVM.CurrentUser.User.Name}"/>
 		<TextBlock Text="Логин"/>

+ 6 - 0
AvaloniaApplication5/Views/PageUserCabinet.axaml.cs

@@ -1,6 +1,10 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Markup.Xaml;
+using Avalonia.Media.Imaging;
+using Avalonia.Platform;
+using System;
+
 
 namespace AvaloniaApplication5.Views;
 
@@ -10,4 +14,6 @@ public partial class PageUserCabinet : UserControl
     {
         InitializeComponent();
     }
+
+    
 }