【问题标题】:Adding events to ScatterViewItems when implicitly creating them隐式创建事件时向 ScatterViewItems 添加事件
【发布时间】:2009-06-03 12:11:15
【问题描述】:

不确定这里有太多的表面开发人员,但是嘿嘿...

如果我有一个 scatterview 隐式创建 ScatterViewItem 对象(见下文),是否可以为每个 scatterViewItem 撤销联系事件?此外,当我明确地将图像对象包装在 ScatterViewItem 中时,该项目不再起作用。谁能告诉我为什么会这样?

<s:ScatterView ItemsSource="{StaticResource DummyData}" >
   <s:ScatterView.ItemTemplate>
      <DataTemplate>
         <Image Source="{Binding Path=ImagePath}" />
      </DataTemplate>
   </s:ScatterView.ItemTemplate>
 </s:ScatterView>

【问题讨论】:

    标签: c# wpf xaml pixelsense


    【解决方案1】:

    将图像包装在数据模板内的 scatterviewitem 中将无济于事,因为只要您使用 ItemsSource,scatterview 仍会生成并用另一个 scatterviewitem 包装它。防止这种情况的唯一方法是在后面的代码中显式地创建并添加 svi 到 scatterview 上的项目集合中,但这会放弃数据绑定的优势。

    为了回答您最初的问题,我假设您想知道在任何生成的 scatterviewitem 上何时发生 ContactDown 或 ContactUp 事件,对吗?由于这些是路由事件,因此您可以在 scatterview 级别订阅。

      <s:ScatterView ItemsSource="{StaticResource DummyData}" 
                     s:ScatterViewItem.ContactDown="OnSVIContactDown">
        <s:ScatterView.ItemTemplate>      
            <DataTemplate>         
               <Image Source="{Binding Path=ImagePath}" />      
            </DataTemplate>   
        </s:ScatterView.ItemTemplate> 
      </s:ScatterView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多