WPf 带滚动条WrapPanel 自动换行 和控件右键菜单
原文:WPf 带滚动条WrapPanel 自动换行 和控件右键菜单
技能点包括 WPf 样式的引用 数据的验证和绑定 比较适合初学者
前台:
-
<Window.Resources>
-
<local:PathToSource x:Key="n2"/>
-
<Style x:Key="{x:Type ContextMenu}" TargetType="{x:Type ContextMenu}">
-
<Setter Property="OverridesDefaultStyle" Value="True"/>
-
<Setter Property="SnapsToDevicePixels" Value="True"/>
-
<Setter Property="Template">
-
<Setter.Value>
-
<ControlTemplate TargetType="{x:Type ContextMenu}">
-
<Border Background="#CD222120" CornerRadius="7, 7, 8, 8" BorderBrush="DarkGray" BorderThickness="2" Opacity="0.96">
-
<StackPanel ClipToBounds="True" Orientation="Vertical" IsItemsHost="True" Margin="5,4,5,4"/>
-
</Border>
-
</ControlTemplate>
-
</Setter.Value>
-
</Setter>
-
</Style>
-
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
-
<Border Name="Border" >
-
<Grid>
-
<ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" />
-
</Grid>
-
</Border>
-
</ControlTemplate>
-
-
<DataTemplate x:Key="Wrapitem">
-
<Grid Height="86" Width="86" >
-
<Grid.ContextMenu>
-
<ContextMenu Name="cm" StaysOpen="true">
-
<MenuItem Header="update"/>
-
<MenuItem Header="Save"/>
-
<MenuItem Header="SaveAs"/>
-
</ContextMenu>
-
-
</Grid.ContextMenu>
-
<Image Margin="8,8,8,24" Source="{Binding Path=Url,Converter={StaticResource n2}}"/>
-
<Label Content="{Binding Path=Text}" Height="22" Width="45" VerticalAlignment="Bottom"/>
-
</Grid>
-
-
</DataTemplate>
-
</Window.Resources>
-
<Grid>
-
<ListBox x:Name="list" Margin="124,63,109,44" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemTemplate="{StaticResource Wrapitem}">
-
<ListBox.Resources>
-
<Style TargetType="ListBoxItem">
-
-
<Style.Resources>
-
-
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFA1A1A1"/>
-
</Style.Resources>
-
</Style>
-
</ListBox.Resources>
-
-
-
<!--<ListBox.ItemsPanel >
-
<ItemsPanelTemplate>
-
<WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
-
</ItemsPanelTemplate>
-
-
</ListBox.ItemsPanel>-->
-
<ListBox.Template>
-
<ControlTemplate TargetType="{x:Type ListBox}">
-
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
-
<WrapPanel Orientation="Horizontal" IsItemsHost="True" ScrollViewer.CanContentScroll="True"/>
-
</ScrollViewer>
-
</ControlTemplate>
-
</ListBox.Template>
-
</ListBox>
-
-
-
-
</Grid>
-
</Window>
后台:
-
/// <summary>
-
/// MainWindow.xaml 的交互逻辑
-
/// </summary>
-
public partial class MainWindow : Window
-
{
-
public MainWindow()
-
{
-
InitializeComponent();
-
load();
-
}
-
-
public void load()
-
{
-
ObservableCollection<Mean> ListMean = new ObservableCollection<Mean>()
-
{
-
new Mean(){Text="001",Url="i"},
-
new Mean(){Text="002",Url="i"},
-
new Mean(){Text="003",Url="ii"},
-
new Mean(){Text="004",Url="i"},
-
new Mean(){Text="005",Url="i"},
-
new Mean(){Text="006",Url="ii"},
-
new Mean(){Text="007",Url="i"},
-
new Mean(){Text="008",Url="i"},
-
new Mean(){Text="009",Url="i"},
-
new Mean(){Text="010",Url="i"},
-
new Mean(){Text="011",Url="ii"},
-
new Mean(){Text="012",Url="i"},
-
new Mean(){Text="013",Url="i"},
-
new Mean(){Text="014",Url="i"},
-
new Mean(){Text="015",Url="i"},
-
new Mean(){Text="016",Url="i"},
-
new Mean(){Text="017",Url="i"}
-
};
-
list.ItemsSource = ListMean;
-
}
-
}
-
public class Mean : INotifyPropertyChanged
-
{
-
private string text;
-
-
public string Text
-
{
-
get { return text; }
-
set { text = value; OnPropertyChanged("Text"); }
-
}
-
private string url;
-
-
public string Url
-
{
-
get { return url; }
-
set { url = value; OnPropertyChanged("Url"); }
-
}
-
-
public event PropertyChangedEventHandler PropertyChanged;
-
-
public void OnPropertyChanged(string propertyName)
-
{
-
-
if (PropertyChanged != null)
-
{
-
-
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
-
-
}
-
-
}
-
}
-
public class PathToSource:IValueConverter
-
{
-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
-
{
-
-
string url = string.Format(@"/Images/{0}.jpg", (string)value=="i"?"i":"ii");
-
return new BitmapImage(new Uri(url,UriKind.Relative));
-
}
-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
-
{
-
throw new NotImplementedException();
-
}
-
}
WPf 带滚动条WrapPanel 自动换行 和控件右键菜单的更多相关文章
- MFC小型工具通用界面框架CLIST控件+右键菜单功能
MFC-小型工具通用界面框架 0x1 场景 由于工作需要我会写代码开发工具给客户或者同事用.代码都能实现,但写个黑乎乎的命令行工具给别人用确实显得不够专业,用别人写好的成型工具又担心有后门. 所以掌握 ...
- FineUI Grid控件右键菜单的实现
FineUI官方Demo上一直没有Grid右键菜单的实现,其实从4.1.x的版本开始,允许添加自定义的事件监听(Listeners),所以要实现这个功能已经相当容易了. ExtJs右键菜单有很多种,对 ...
- win32 listctrl控件右键菜单的实现
HMENU Menu_list,Menu_all; POINT point; HINSTANCE hInstance;//下面代码放到BOOL WINAPI DialogProc下 case WM_C ...
- WPF中不规则窗体与WebBrowser控件的兼容问题解决办法
原文:WPF中不规则窗体与WebBrowser控件的兼容问题解决办法 引言 这几天受委托开发一个网络电视项目,要求初步先使用内嵌网页形式实现视频播放和选单,以后再考虑将网页中的所有功能整合进桌面程序. ...
- WPF自定义控件(五)の用户控件(完结)
用户控件,WPF中是继承自UserControl的控件,我们可以在里面融合我们的业务逻辑. 示例:(一个厌恶选择的用户控件) 后端: using iMicClassBase; using iMicCl ...
- Git使用总结 Asp.net生命周期与Http协议 托管代码与非托管代码的区别 通过IEnumerable接口遍历数据 依赖注入与控制反转 C#多线程——优先级 AutoFac容器初步 C#特性详解 C#特性详解 WPF 可触摸移动的ScrollViewer控件 .NET(C#)能开发出什么样的APP?盘点那些通过Smobiler开发的移动应用
一,原理 首先,我们要明白Git是什么,它是一个管理工具或软件,用来管理什么的呢?当然是在软件开发过程中管理软件或者文件的不同版本的工具,一些作家也可以用这个管理自己创作的文本文件,由Linus开发的 ...
- 封装:WPF中可以绑定的BindPassWord控件
原文:封装:WPF中可以绑定的BindPassWord控件 一.目的:本身自带的PassWord不支持绑定 二.Xaml部分 <UserControl x:Class="HeBianG ...
- WPF布局之让你的控件随着窗口等比放大缩小,适应多分辨率满屏填充应用
一直以来,我们设计windows应用程序,都是将控件的尺寸定好,无论窗体大小怎么变,都不会改变,这样的设计对于一般的应用程序来说是没有问题的,但是对于一些比较特殊的应用,比如有背景图片的,需要铺面整个 ...
- WPF自定义控件与样式(9)-树控件TreeView与菜单Menu-ContextMenu
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 菜单M ...
随机推荐
- SSM框架之SpringMVC(3)常用注解
SpringMVC(3)常用注解 1. RequestParam注解 1.作用:把请求中指定名称的参数传递给控制器中的形参赋值 2.属性: 1.value:请求参数的每次 2.required ...
- echarts 双Y轴图表
直接代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 前端最佳实践——DOM操作
1.浏览器渲染原理 在讲DOM操作的最佳性能实践之前,先介绍下浏览器的基本渲染原理. 分为以下四个步骤: 解析HTML(HTML Parser) 构建DOM树(DOM Tree) 渲染树构建(Rend ...
- C lang:The smallest negative plus one equals the largest positive
- 一、VUE项目BaseCms系列文章:项目介绍与环境配置
一.项目效果图预览: 二.项目介绍 基于 elementui 写一个自己的管理后台.这个系列文章的目的就是记录自己搭建整个管理后台的过程,希望能帮助到那些入门 vue + elementui 开发的小 ...
- 使用“npm init”初始化项目
使用npm init初始化项目 为什么要使用npm init初始化项目 在node开发中使用npm init会生成一个pakeage.json文件,这个文件主要是用来记录这个项目的详细信息的,它会将我 ...
- Linux禁用root用户
在创建各种云主机的时候,云服务商给的都是root用户,这很方便,但是有某些时候会造成一些困扰,日后在服务器上启动各种服务后,仅仅拥有root权限的用户才能访问更改这些服务,这样会造成一些不必要的困扰, ...
- MySQL常用DDL、DML、DCL语言整理
DDL ----Data Definition Language 数据库定义语言 如 create procedure之类 创建数据库 CREATE DATABASE [IF NOT EXISTS] ...
- react生命周期函数的应用-----1性能优化 2发ajax请求
知识点1:每次render其实就会将jax的模板生成一个虚拟dom,跟上一个虚拟dom进行比对,通过diff算法找出不同,再更新到真实dom上去. 1性能优化 每次父组件render一次(除了第一次初 ...
- 「Shimo使用指南」mac支持pptp协议的小软件
Mac的好多小伙伴在访问网络设备时觉得远程连接不方便,例如ssh,***登陆都不是很方便,后来又安装了open*** forMac.ISSH等客户端,使用后发现不是很稳定,断线后很久都无法连接等缺点, ...