在ItemsControl中流汗所选项目 [英] Gettting selected item in ItemsControl

查看:176
本文介绍了在ItemsControl中流汗所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code这填充的行和列的形式我的用户控件。正在被填充的用户控件包含按钮,链接,文本框等。当某个按钮是在一个特定的行/列pssed在一个特定的用户控件$ P $,我需要知道哪个用户控制该按钮是pressed。这里是填充以行和列的用户控制的XAML

I have the following code which populates my user control in form of rows and column. The user control which is being populated contains Button, links, textbox etc. When a certain button is pressed on a particular User Control in a particular row/column, I need to know for which User Control that button was pressed. Here is the XAML that is populating the user controls in rows and columns

  <ItemsControl ItemsSource="{Binding Templates}" Width="{Binding GridWidth}">
        <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                    <UniformGrid Columns="{Binding NumColumns}" />
              </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
              <ItemsControl.ItemContainerStyle>
                 <Style>
                     <Setter Property="Grid.Column" Value="{Binding ColumnIndex}" />
                     <Setter Property="Grid.Row" Value="{Binding RowIndex}" />
                  </Style>
                 </ItemsControl.ItemContainerStyle>
                 <ItemsControl.ItemTemplate>
  </ItemsControl>

模板基本上是被填充的行/列用户控件的集合。
preferably我想这样做,在视图模型,但在后面,现在code解决方案将正常工作。

Templates is basically a collection of UserControls that are being populated in Rows/Columns. Preferably I want to do this in ViewModel but solution in code behind for now will work as well.

在事先非常感谢:)

推荐答案

的ItemsControl 无法选择的项目,只有present集合。只有<一个href=\"http://msdn.microsoft.com/en-us/library/System.Windows.Controls.Primitives.Selector.aspx\">Selector或者它的一个后代可以选择的项目。

ItemsControl can't select items, only present collections. Only a Selector or one of it's descendants can select items.

有关您的情况,我觉得的ListView ,提供的GridView 将适合。当用户将在线路点击控制,事件会泡到的ListView ,而该项目会得到选择。您可以覆盖的默认样式所以它不会显示为选定的线路: WPF ListView的关闭选择

For your scenario, I think a ListView with GridView would fit. When the user would click a control in the line, the event would bubble to the ListView and the item would get selected. You can override the default styles so it wouldn't display as selected line: WPF ListView turn off selection.

这篇关于在ItemsControl中流汗所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆