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. ...
随机推荐
- Android 获取签名证书的具体信息(Eclipse和Android studio通用)
今天要用到签名证书的MD5,可是这个仅仅有在第一次生成的时候我看到了,这可怎么办呢,幸亏我们有google,我们执行以下的命令就OK了. keytool -list -v -keystore 签名证书 ...
- Android 在Service里面启动Activity
直接在代码: Intent dialogIntent = new Intent(getBaseContext(), YourActivity.class); dialogIntent.addFlags ...
- 二、Reids基础命令--字符串
11.一个字符串类型的KEY同意存储的数据的最大容量是 512MB 12.INCR 使key加1,key不存在时默认是0 . 返回递增后的值. 127.0.0.1:6379> incr num ...
- Chrome源代码结构
首先,开始接触Chrome的童鞋可能有一个疑惑,Chrome和Chromium是同一个东西吗?答案是,Chrome是Google官方的浏览器项目名称,Chromium是Google官方对Chrome开 ...
- Windows7系统下安装OpenSSL攻略
Windows7系统下安装OpenSSL攻略 http://blog.chinaunix.net/uid-20479991-id-216269.html http://my.oschina.net/s ...
- 数据序列化之protobuf
数据序列化之protobuf 很多时候需要将一些数据打包,就是把这些数据搞在一起,方便处理.最常见的情况就是把需要传输的数据,当然数据不止一条,打包成一个消息,然后发送出去,接收端再以一定的规则接收并 ...
- ssh连接上腾讯云、华为云Linux服务器,一会就自动断开
客户端向服务端发送心跳 依赖 ssh 客户端定时发送心跳,putty.SecureCRT.XShell 都有这个功能. Linux / Unix 下,编辑 ssh 配置文件: # vim /etc/s ...
- 设置非ARC
设置非ARC: 在build phase 设置中compile sources 选择非arc文件,设置键值为-fno-objc-arc
- C#编写TensorFlow人工智能应用
C#编写TensorFlow人工智能应用 TensorFlowSharp入门使用C#编写TensorFlow人工智能应用学习. TensorFlow简单介绍 TensorFlow 是谷歌的第二代机器学 ...
- 一起学Python:字典介绍
字典介绍 想一想: 如果有列表 nameList = ['xiaoZhang', 'xiaoWang', 'xiaoLi']; 需要对"xiaoWang"这个名字写错了,通过代码修 ...