博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF listview item mouse enter/over popup
阅读量:7005 次
发布时间:2019-06-27

本文共 3365 字,大约阅读时间需要 11 分钟。

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 Blocknamespace ForumProjects{    public partial class MainWindow : Window    {        public MainWindow()        {            this.Persons = new List
() { 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
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; } } }}
Best Regards,Wei Zhou

 

原文:

none
 
 

转载地址:http://raytl.baihongyu.com/

你可能感兴趣的文章
B1036. 跟奥巴马一起编程(15)
查看>>
软件项目后期收官时的一些问题和想法
查看>>
机器学习:线性回归
查看>>
PHP连接PostgreSQL连接问题
查看>>
WebService案例入门(基础篇)
查看>>
回档|NOIP2012 同余方程
查看>>
久违的博客园
查看>>
Alpha冲刺(9/10)
查看>>
【转】B树的插入和删除
查看>>
一个小案例明白onLayout()、onMeasure()方法的作用
查看>>
陶哲轩实分析定理 11.4.3 $\max$与$\min$保持黎曼可积性
查看>>
SIP、Mobicents扫盲
查看>>
rest-framework-版本控制
查看>>
android wifi obtainmessage sendmessage解析
查看>>
总结spring下配置dbcp,c3p0,proxool数据源链接池
查看>>
不再消极,不再忧虑
查看>>
我的模块加载系统 v20
查看>>
简明Python3教程 5.第一步
查看>>
SharePoint 搜索爬网第三方网站配置
查看>>
总结Movie示例知识点
查看>>