Parcourir la source

сделали галерею для пользователей

ЧернощековаАР il y a 1 semaine
Parent
commit
01da041962

+ 5 - 0
AvaloniaApplication2/Res/DateConverter.cs

@@ -1,7 +1,9 @@
 using Avalonia.Data.Converters;
+using Avalonia.Media.Imaging;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -14,6 +16,7 @@ namespace AvaloniaApplication2.Resources
         public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
         {         
             if (value is DateTime) return new DateTimeOffset((DateTime)value, TimeSpan.Zero); 
+            if (value is byte[]) return new Bitmap(new MemoryStream((byte[])value));
             return null;
         }
 
@@ -26,5 +29,7 @@ namespace AvaloniaApplication2.Resources
             }
             return null;
         }
+        
+
     }
 }

+ 1 - 1
AvaloniaApplication2/ViewModels/UserProfileForAdminViewModel.cs

@@ -37,7 +37,7 @@ namespace AvaloniaApplication2.ViewModels
             GendersList = db.Genders.ToList();
             editedLogin = db.Logineds.Include(x => x.User.GenderNavigation).Include(x => x.User.Idtraits).FirstOrDefault(x => x.Id == id);
             imageUser = EditedLogin.User.Image != null ? new Bitmap(new MemoryStream(editedLogin.User.Image)) : new Bitmap("C:/Users/ЧернощековаАР/source/repos/AvaloniaApplication2/AvaloniaApplication2/Assets/профиль.png");
-            Images = new ObservableCollection<Bitmap>();
+            
         }
 
         public DateTimeOffset DateTimeOffset

+ 6 - 1
AvaloniaApplication2/ViewModels/UserProfileViewModel.cs

@@ -15,6 +15,7 @@ using Avalonia.Controls.ApplicationLifetimes;
 using System.Threading.Tasks;
 using System.Collections.ObjectModel;
 using System.Security.Policy;
+using Avalonia.Interactivity;
 
 namespace AvaloniaApplication2.ViewModels
 {
@@ -35,7 +36,7 @@ namespace AvaloniaApplication2.ViewModels
         public UserProfileViewModel(int id)
         {
             GendersList = db.Genders.ToList();
-            editedLogin = db.Logineds.Include(x => x.User.GenderNavigation).Include(x=>x.User.Idtraits).FirstOrDefault(x => x.User.IdUser == id);
+            editedLogin = db.Logineds.Include(x => x.User.GenderNavigation).Include(x=>x.User.Idtraits).Include(x=>x.User.Userimages).FirstOrDefault(x => x.User.IdUser == id);
             imageUser = EditedLogin.User.Image != null ? new Bitmap(new MemoryStream(editedLogin.User.Image)) : new Bitmap("C:/Users/ЧернощековаАР/source/repos/AvaloniaApplication2/AvaloniaApplication2/Assets/профиль.png");
             Images = new ObservableCollection<Bitmap>();
         }
@@ -95,6 +96,8 @@ namespace AvaloniaApplication2.ViewModels
             }
         }
 
+        public void OpenImages() => MainWindowViewModel.Self.Page = new UsersGallary();
+
         public void DeleteImage(int id)
         {
             Userimage deletedImage = db.Userimages.FirstOrDefault(x => x.Id == id);
@@ -102,5 +105,7 @@ namespace AvaloniaApplication2.ViewModels
             db.SaveChanges();
             MainWindowViewModel.Self.Page = new UsersGallary();
         }
+
+        
     }
 }

+ 1 - 1
AvaloniaApplication2/Views/UserProfile.axaml

@@ -41,7 +41,7 @@
 		</StackPanel>
 		<Button Command="{Binding UserProfileVM.Save}" Content="СОХРАНИТЬ ИЗМЕНЕНИЯ" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
 		<Button Content="Добавить изображение пользователя" Command="{Binding UserProfileVM.Image}" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
-		<Button Content="Посмотреть все фото пользователя" Command="" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<Button Content="Посмотреть все фото пользователя" Command="{Binding UserProfileVM.OpenImages}" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
 		<Button Command="{Binding UserProfileVM.GoBack}" Content="ВЫХОД" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
 		<TextBlock Text="Развлекаловка" HorizontalAlignment="Center" VerticalAlignment="Bottom" Classes="AnimatedTB" Padding="0,40,0,0"/>
 	</StackPanel>

+ 8 - 2
AvaloniaApplication2/Views/UsersGallary.axaml

@@ -6,17 +6,23 @@
              x:Class="AvaloniaApplication2.UsersGallary"
 			 xmlns:vm="using:AvaloniaApplication2.ViewModels"
 			 x:DataType="vm:MainWindowViewModel"
+			 xmlns:conv="using:AvaloniaApplication2.Resources"
 			 Background="LightGray">
+	<UserControl.Resources>
+		<conv:DateConverter x:Key="BitmapConverter"/>
+	</UserControl.Resources>
+
 	<Panel>
 		<ListBox ItemsSource="{Binding UserProfileVM.EditedLogin.User.Userimages}">
 			<ListBox.ItemTemplate>
 				<DataTemplate>
-					<StackPanel Orientation="Horizontal">
-						<Image Source="{Binding Image}"/>
+					<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
+						<Image Source="{Binding Image, Converter = {StaticResource BitmapConverter}}" Width="200" Height="200"/>
 						<Button Content="Удалить картинку" Command="{Binding $parent[UserControl].((vm:UserProfileViewModel)DataContext).DeleteImage}" CommandParameter="{Binding Id}"/>
 					</StackPanel>
 				</DataTemplate>
 			</ListBox.ItemTemplate>
 		</ListBox>
 	</Panel>
+
 </UserControl>

+ 0 - 2
AvaloniaApplication2/Views/UsersGallary.axaml.cs

@@ -1,6 +1,5 @@
 using Avalonia;
 using Avalonia.Controls;
-using Avalonia.Interactivity;
 using Avalonia.Markup.Xaml;
 using AvaloniaApplication2.ViewModels;
 
@@ -11,6 +10,5 @@ public partial class UsersGallary : UserControl
     public UsersGallary()
     {
         InitializeComponent();
-        DataContext = new UserProfileViewModel();
     }
 }