Skip to content

Commit

Permalink
Added Image Item (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Feb 21, 2024
1 parent 94faf4f commit e2d1132
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
51 changes: 51 additions & 0 deletions ColorPicker/UserControls/ImageItem.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<UserControl
x:Class="ColorPicker.UserControls.ImageItem"
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:lang="clr-namespace:ColorPicker.Properties"
xmlns:local="clr-namespace:ColorPicker.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="400"
Height="250"
mc:Ignorable="d">
<Border
Margin="5"
d:Background="white"
CornerRadius="10">
<Border.Background>
<ImageBrush x:Name="Img" Stretch="UniformToFill" />
</Border.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Button
x:Name="DeleteBtn"
Grid.Column="3"
Margin="0 5 5 0"
Padding="5"
VerticalAlignment="Top"
Background="{DynamicResource Background3}"
Click="DeleteBtn_Click"
Content="&#xF34D;"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource DefaultButton}">
<Button.ToolTip>
<ToolTip
Background="{DynamicResource Background1}"
Content="{x:Static lang:Resources.RemoveImage}"
Foreground="{DynamicResource Foreground1}" />
</Button.ToolTip>
</Button>
</Grid>
</Border>
</UserControl>
73 changes: 73 additions & 0 deletions ColorPicker/UserControls/ImageItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace ColorPicker.UserControls
{
/// <summary>
/// Interaction logic for ImageItem.xaml
/// </summary>
public partial class ImageItem : UserControl
{
public string Path { get; }
public ImageItem(string path)
{
InitializeComponent();
Path = path;
InitUI();
}


private void InitUI()
{
try
{
var bitmap = new BitmapImage();
var stream = File.OpenRead(Path);
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = stream;
bitmap.DecodePixelWidth = 256;
bitmap.EndInit();
stream.Close();
stream.Dispose();
bitmap.Freeze();
Img.ImageSource = bitmap;
}
catch
{

}
}

private void DeleteBtn_Click(object sender, RoutedEventArgs e)
{

}
}
}

0 comments on commit e2d1132

Please sign in to comment.