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
)
- 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 数组属性和方法
- PAT (Basic Level) Practice (中文)1063 计算谱半径
- PAT (Basic Level) Practice (中文)1064 朋友数
- PAT (Basic Level) Practice (中文)1076 Wifi密码
- PAT (Basic Level) Practice (中文)1077 互评成绩计算
- PAT (Basic Level) Practice (中文)1081 检查密码
- PAT (Basic Level) Practice (中文)1082 射击比赛
- PAT (Basic Level) Practice (中文)1083 是否存在相等的差
- 2017年天梯赛全国总决赛题集 L2-1 点赞狂魔
- 2017年天梯赛全国总决赛题集 L1-4 稳赢
- 2017年天梯赛全国总决赛题集 L1-8 矩阵A乘以B
- 你真的了解synchronized吗?
- 2017年天梯赛大区赛题集 7-1 出生年
- 2017年天梯赛大区赛题集 7-9 人以群分
- 浙大版《C语言程序设计(第3版)》题目集 练习2-1 Programming in C is fun!
- 浙大版《C语言程序设计(第3版)》题目集 练习2-3 输出倒三角图案