<Window.Resources>
<DataTemplate x:Key="PathTemplate">
<TextBox Width="220"></TextBox>
</DataTemplate>
</Window.Resources>
这里面的TextBox没有名称,因为我要使用该模板在ListView中创建很多TextBox,如何获得当光标放入某个创建的TextBox内后,能够获得该TextBox的右键点击事件?谢谢!
<DataTemplate x:Key="PathTemplate">
<TextBox Width="220"></TextBox>
</DataTemplate>
</Window.Resources>
这里面的TextBox没有名称,因为我要使用该模板在ListView中创建很多TextBox,如何获得当光标放入某个创建的TextBox内后,能够获得该TextBox的右键点击事件?谢谢!
因为我的ListView中有一列都是TextBox,这一列TextBox如上面的定义,是没有名字的,如何对某一个TextBox传值?
{
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(dpObj); i++)
{
var child = VisualTreeHelper.GetChild(dpObj, i);
TextBox tb = child as TextBox;
if (tb != null)
{
if(!tbList.Contains(tb))
{
tbList.Add(tb);
}
}
else
{
GetTextBox(child,tbList);
}
}
} private void OnCollectAllTextBox(object sender, RoutedEventArgs e)
{
List<TextBox> tbList = new List<TextBox>();
GetTextBox(listView1, tbList); tbList.ForEach(tb =>
{
//Register mouse right button down event
tb.PreviewMouseRightButtonDown += (s,arg)=>
{
tb.Text = "Mouse right button down";
//Cancel the event routing
arg.Handled = true;
};
});
}