WPF listview item mouse enter/over popup
This is because the routing strategy of the Loaded event is Direct, which means that the routed event does not route though an element tree. This is why we are unable to catch the Loaded event from the ListViewItems. You can refer to the doucment of Loaded event to get more information about this. The following example shows how to do this.
Code Block
namespace ForumProjects
{
public partial class MainWindow : Window
{
public MainWindow()
{
this.Persons = new List<Person>()
{
new Person(){ID=1,Name="AAA",Comment="Comment AAA"},
new Person(){ID=2,Name="BBB",Comment="Comment BBB"},
new Person(){ID=3,Name="CCC",Comment="Comment CCC"},
new Person(){ID=4,Name="DDD",Comment="Comment DDD"},
};
InitializeComponent();
}
public List<Person> Persons { get; private set; }
}
public class Person
{
public int ID { get; set; }
public string Name { get; set; }
public string Comment { get; set; }
}
public class PersonListView : ListView
{
protected override DependencyObject GetContainerForItemOverride()
{
return new PersonListViewItem();
}
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is PersonListViewItem;
}
}
public class PersonListViewItem : ListViewItem
{
public static readonly DependencyProperty PopupTextProperty =
DependencyProperty.Register("PopupText", typeof(string), typeof(PersonListViewItem), new FrameworkPropertyMetadata(PopupTextChanged));
public static readonly DependencyProperty IsPopupOpenProperty =
DependencyProperty.Register("IsPopupOpen", typeof(bool), typeof(PersonListViewItem), new FrameworkPropertyMetadata(IsPopupOpenChanged));
private Popup popup;
private TextBlock textBlock;
public PersonListViewItem()
{
this.textBlock = new TextBlock();
Grid grid = new Grid() { Background = Brushes.White };
grid.Children.Add(this.textBlock);
this.popup = new Popup() { Child = grid, PlacementTarget = this, Placement = PlacementMode.Right };
}
public string PopupText
{
get { return (string)GetValue(PopupTextProperty); }
set { SetValue(PopupTextProperty, value); }
}
public bool IsPopupOpen
{
get { return (bool)GetValue(IsPopupOpenProperty); }
set { SetValue(IsPopupOpenProperty, value); }
}
private static void IsPopupOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
PersonListViewItem item = d as PersonListViewItem;
if (item != null)
{
item.popup.IsOpen = (bool)e.NewValue;
}
}
private static void PopupTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
PersonListViewItem item = d as PersonListViewItem;
if (item != null)
{
item.textBlock.Text = (string)e.NewValue;
}
}
}
}
<Window x:Class="ForumProjects.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ForumProjects"
x:Name="Window" Title="MainWindow" Height="700" Width="800">
<StackPanel>
<local:PersonListView ItemsSource="{Binding ElementName=Window, Path=Persons}">
<local:PersonListView.View>
<GridView>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}"/>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
</GridView>
</local:PersonListView.View>
<local:PersonListView.ItemContainerStyle>
<Style TargetType="local:PersonListViewItem">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsPopupOpen" Value="True"/>
</Trigger>
</Style.Triggers>
<Setter Property="PopupText" Value="{Binding Comment}"/>
</Style>
</local:PersonListView.ItemContainerStyle>
</local:PersonListView>
</StackPanel>
</Window>
Best Regards,
Wei Zhou
原文:WPF listview item mouse enter/over popup

WPF listview item mouse enter/over popup的更多相关文章
- C# Note16: wpf window 中添加enter和双击事件
一.添加回车(enter)事件 在C#编程时,有时希望通过按回车键,控件焦点就会自动从一个控件跳转到下一个控件进行操作. 以用户登录为例,当输入完用户名和密码后, 需要点击登录按钮,而登录按钮必须获 ...
- WPF ListView 选中问题
WPF ListView 选中问题 摘自:http://www.cnblogs.com/BBHor/archive/2013/04/28/VisualTreeHelper-PreviewMouseD ...
- WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画
原文:WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画 利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同 ...
- Android listview.item.clear()与listview.clear()的区别
listview.clear()与listview.item.clear()的区别就是使用了listview.item.clear()后,listview控件中仍然保存着listviewitem项的结 ...
- ListView item 中TextView 如何获取长按事件
昨天晚上小伙伴突然来信, ListView item中嵌套的TextView 无法获取长按事件 从前从来没有仔细留意过, coding后发现...果然没什么动静 而且没有合适的API让我调用获取Tex ...
- [WPF]ListView点击列头排序功能实现
[转] [WPF]ListView点击列头排序功能实现 这是一个非常常见的功能,要求也很简单,在Column Header上显示一个小三角表示表示现在是在哪个Header上的正序还是倒序就可以了. ...
- Android 原生listview item伸展收缩效果 (续)
接上一个原生的listview item的伸展收缩效果. 上一个可能做的有些粗糙,效果也没有这个好,上代码. package com.example.listviewdemo; import java ...
- Android 原生listview item伸展收缩效果
Android原生listview做的一个item的伸缩效果.*永远不要让你老大有机会改需求 package com.example.yunkanglast; import java.io.Seria ...
- android 修改listview item view 的方法(转)
android 修改listview item view 的方法 具体的解答办法很简单: 代码如下 : 1.获取需要更新的view int visiblePosition = mListView. ...
随机推荐
- inflate, findViewById与setContentView的区别与联系 分类: H1_ANDROID 2014-04-18 22:54 1119人阅读 评论(0) 收藏
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...
- IIS最大并发连接数 = 队列长度 + IIS最大并发工作线程数
深入理解IIS的多线程工作机制 首先让我们来看看IIS里面的这2个数字:最大并发连接数,队列长度.先说这2个数字在哪里看. 最大并发连接数:在IIS中选中一个网站,右键网站名称,在右键菜单中找到并 ...
- jquery获取元素坐标获取鼠标坐标
获取页面某一元素的绝对X,Y坐标,可以用offset()方法: var X = $('#DivID').offset().top; var Y = $('#DivID').offset().left; ...
- js进阶 11-7 jquery如何获取和改变元素的位置
js进阶 11-7 jquery如何获取和改变元素的位置 一.总结 一句话总结:jquery中匿名函数中的index参数是什么意思.jquery对象多集合,故index为所选元素的下标. 1.jqu ...
- 解决ThinkPad x1 发热的问题
F1进入BIOS界面 将intel speedstep设置为禁用 将CPU Power Manager设置为禁用 重启电脑 电脑不再发热
- Linux删除非空目录
Linux下如何删除非空目录 这个问题很basic,不过还是困扰了我一段时间.(这里主要讨论的是命令行模式下)我本来觉得应该使用命令 rmdir但是发现它无法删除非空的目录.后来发现了原来应该使用 ...
- PHP移动互联网开发笔记(4)——自定义函数及数组
一.自定义函数 自定义函数就是我们自己定义的函数,在PHP中自定义函数格式如下: function funname(arg1, arg2, arg3......){ //TODO return val ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- webtool小问题
webtool小问题 erlang的观察工具如crashdump,appmon,cover等工具有二种不同的界面:gs(wx)和web.这些tool都遵循一定的接口,用户可以自行扩展这些功能,使的能够 ...
- Docker Xshell
Windows安装Docker Xshell无法连接虚拟机解决方案 DOCKER windows安装 6.1 下载地址 6.2 用FTP工具上传tar包 6.3 安装 6.4 查看镜像 6.5 运行 ...