【问题标题】:UWP XAMl ListView Item Template MVVM EventsUWP XAMl ListView 项目模板 MVVM 事件
【发布时间】:2019-04-30 09:57:19
【问题描述】:

如果我想实现 MVVM 模式。在 ListView.ItemTemplate 的 Datatemplate 内的 TextBlock 上实现诸如 DoubletTapped 之类的事件的正确过程是什么?

<ListView.ItemTemplate>
     <DataTemplate x:DataType="classes:Person">
         <TextBlock
            DoubleTapped="{x:Bind}"//what goes here to call a method on the ViewModel
            Foreground="Green"
            Text="{x:Bind Name}" />
    </DataTemplate>
</ListView.ItemTemplate>

【问题讨论】:

    标签: xaml uwp


    【解决方案1】:

    请修改您的TextBlock Xaml 如下:

    <TextBlock Foreground="Green" Text="{x:Bind Name}" >
          <interactivity:Interaction.Behaviors>
             <core:EventTriggerBehavior EventName="DoubleTapped">
                   <core:InvokeCommandAction  Command="{Binding ElementName=RootPage, Path=DataContext.YourCommandMethod}"/>
              </core:EventTriggerBehavior>     
           </interactivity:Interaction.Behaviors>
     </TextBlock>
    

    RootPage 是根元素的名称,在我的例子中是 Page

    【讨论】:

      猜你喜欢
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 2018-10-10
      • 1970-01-01
      • 2020-01-19
      • 2017-04-24
      • 1970-01-01
      相关资源
      最近更新 更多