Untitled
unknown
plain_text
a year ago
1.5 kB
6
Indexable
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace YourNamespace
{
public partial class PostControl : UserControl
{
private bool isLiked = false;
public string ImagePath { get; set; }
public string HeartEmptyPath { get; set; } = @"C:\Path\To\EmptyHeart.png";
public string HeartFilledPath { get; set; } = @"C:\Path\To\FilledHeart.png";
public string SendButtonPath { get; set; } = @"C:\Path\To\SendButton.png";
public PostControl()
{
InitializeComponent();
HeartImage.Source = new BitmapImage(new Uri(HeartEmptyPath, UriKind.Absolute));
SendButtonImage.Source = new BitmapImage(new Uri(SendButtonPath, UriKind.Absolute));
}
public void SetPostImage(string path)
{
ImagePath = path;
PostImage.Source = new BitmapImage(new Uri(ImagePath, UriKind.Absolute));
}
private void PostImage_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
ToggleHeart();
}
private void HeartImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ToggleHeart();
}
private void ToggleHeart()
{
isLiked = !isLiked;
HeartImage.Source = new BitmapImage(new Uri(isLiked ? HeartFilledPath : HeartEmptyPath, UriKind.Absolute));
}
}
}Editor is loading...
Leave a Comment