wpf listBox 多列大图片效果
时间:2022-04-25
本文章向大家介绍wpf listBox 多列大图片效果,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
修改ListBox的模版 多列大图片效果,加上删除button
看图
上代码!
<Window x:Class="Thunder.SetCenter.RoomSetting.ActivityPhotoView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Thunder.SetCenter.RoomSetting"
xmlns:convertImage="clr-namespace:Thunder.SetCenter.FoodSetting"
Title="活动图片" Height="700" Width="850" Loaded="WinLoadedEvent">
<Window.Resources>
<convertImage:ConvertToRecipesImageInfo x:Key="ImageConverter"></convertImage:ConvertToRecipesImageInfo>
<DataTemplate x:Key="ItemTemplate">
<Grid Width="200" Height="210" >
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="SingleWidthColumn" ></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.Style>
<Style>
<Setter Property="TextBlock.Foreground" Value="Transparent"></Setter>
</Style>
</Grid.Style>
<Border Margin="2" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="3">
<Grid Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="185"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding Path=activePricture,Converter={StaticResource ImageConverter}}" Margin="0" ></Image>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" >
<Button Width="20" BorderThickness="0" Background="Transparent" Click="Del_PrictureEvent" Name="btn_Del" Tag="{Binding Path=id}" Style="{StaticResource CloseButton}" >
</Button>
</StackPanel>
</Grid>
</Border>
</Grid>
</DataTemplate>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Style.Resources>
<!--SelectedItem with focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue" Opacity=".4"/>
</Style.Resources>
</Style>
</Window.Resources>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="589"></RowDefinition>
<RowDefinition Height="73"></RowDefinition>
<RowDefinition Height="24*" />
</Grid.RowDefinitions>
<ListBox Grid.IsSharedSizeScope="True" Grid.Row="0" Margin="5" Name="lsPricture" ItemTemplate="{StaticResource ItemTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" SnapsToDevicePixels="True">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Background="#F3FFFF" >
</WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Content="添加 " Margin="0,17,10,21" Width="120" Click="btn_AddEvent"></Button>
<TextBlock VerticalAlignment="Center" Margin="0,35,10,21">
<Hyperlink Name="hpl_Back" Style="{StaticResource hpl_BackStyle}" Click="hpl_Back_Click">返回 Esc</Hyperlink>
</TextBlock>
</StackPanel>
</Grid>
</Window>
#region ConverToImageInfo 把DataTable里的转换成图片
[System.Windows.Data.ValueConversion(typeof(byte[]),typeof(ImageSource))]
public class ConvertToRecipesImageInfo:System.Windows.Data.IValueConverter
{
#region IValueConverter 成员
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
byte[] binaryimagedata=value as byte[];
if (binaryimagedata == null) return "";
using(Stream imageStreamSource =new MemoryStream(binaryimagedata,false))
{
JpegBitmapDecoder jpeDecoder=new JpegBitmapDecoder(imageStreamSource,BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.OnLoad);
ImageSource imageSource=jpeDecoder.Frames[0];
return imageSource;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
#endregion
<!--关闭按钮样式-->
<Style x:Key="CloseButton" TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="Transparent">
<Canvas>
<Line X1="4" Y1="4" X2="11" Y2="11" Stroke="#9FA1A0" StrokeThickness="2"></Line>
<Line X1="11" Y1="4" X2="4" Y2="11" Stroke="#9FA1A0" StrokeThickness="2"></Line>
</Canvas>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ThunderSetCenterBLL.RoomSetting;
using System.Data;
namespace Thunder.SetCenter.RoomSetting
{
/// <summary>
/// ActivityPhotoView.xaml 的交互逻辑
/// </summary>
public partial class ActivityPhotoView : Window
{
#region Value
private ActivityPrictureBLL bll_ActivityPrictureBLL = new ActivityPrictureBLL();
#endregion
#region Ini And WinEvent
public ActivityPhotoView()
{
InitializeComponent();
}
public void WinLoadedEvent(object sender, RoutedEventArgs e)
{
BindingData();
}
#endregion
#region Add Del Binding
/// <summary>
/// 绑定
/// </summary>
public void BindingData()
{
DataTable _BingData = bll_ActivityPrictureBLL.GetAcitviPricture();
lsPricture.ItemsSource = _BingData.DefaultView;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Del_PrictureEvent(object sender, RoutedEventArgs e)
{
Button _DelBtn = sender as Button;
int _delID = (int)_DelBtn.Tag;
}
public void btn_AddEvent(object sender, RoutedEventArgs e)
{
}
public void hpl_Back_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
#endregion
}
}
create table activePricture
(
id int identity(1,1),
activeName varchar(50),
activePricture image
)
- 两条报警信息的分析(第二篇)(r6笔记第71天)
- 两条报警信息的分析(第一篇) (r6笔记第70天)
- R-求y=sin(X) 0-PI 面积代码
- Facebook 发布 wav2letter 工具包,用于端到端自动语音识别
- Java企业面试——Java基础
- 从Java的类型转换看MySQL和Oracle中的隐式转换(二)(r6笔记第68天)
- R包—iGraph
- 深度学习中 GPU 和显存分析
- 数据库SQL优化大总结1之- 百万级数据库优化方案
- Golang语言社区--LollipopGO开源项目搭建商城路由分发
- Shapes and line types for R
- Python基本常用包整理(data analysis and machine learning),附查询包版本语句
- 一次 PyTorch 的踩坑经历,以及如何避免梯度成为NaN
- 递归与伪递归区别,Python 实现递归与尾递归
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Ascgen2可以把图片变成文字的小工具
- 解决android studio卡顿,提升studio运行速度的方法
- Android物理键盘事件解析
- AndroidQ(10)分区存储完美适配方法
- (全局快捷键工具)Power Keys彻底提升码字效率?
- android自定义view实现钟表效果
- 教你如何用OpenVZ限制虚拟机硬盘IO速度
- Android自定义控件实现短信验证码自动填充
- android studio 3.6.1升级后如何处理 flutter问题
- Android项目迁移到AndroidX的方法步骤
- Android中layer-list基本使用详解
- Android Studio中主题样式的使用方法详解
- android点击无效验证的解决方法
- Android Studio 3.5格式化布局代码时错位、错乱bug的解决
- Android实现时钟特效