[英]WP8: LongListMultiSelector Tap Item Trigger MVVM
Another question concerning the LongListMultiSelector (Windows Phone 8 Toolkit). 关于LongListMultiSelector(Windows Phone 8 Toolkit)的另一个问题。 I want to start a command when tapping on a single item in the LongListMultiSelector.
在LongListMultiSelector中点击单个项目时,我想启动命令。
XAML XAML
<local:LongListMultiSelector
x:Name="FileList"
ItemsSource ="{Binding CurrentFileList}"
EnforceIsSelectionEnabled="{Binding IsInSelectionMode}"
toolkit:TiltEffect.IsTiltEnabled="True"
IsSelectionEnabled="True"
ItemContainerStyle="{StaticResource FileBrowserLongListMultiSelectorStyle}"
SelectedFiles="{Binding SelectedFiles}">
<local:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,20">
<Rectangle Width="80" Height="80" Fill="{StaticResource BoxCryptorGreenBrush}"/>
<StackPanel Margin="10,0">
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}"/>
<TextBlock Text="{Binding Size}" Style="{StaticResource PhoneTextSmallStyle}"/>
</StackPanel>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<i:InvokeCommandAction Command="{Binding TapOnFileCommand}" CommandParameter="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</StackPanel>
</DataTemplate>
</local:LongListMultiSelector.ItemTemplate>
</local:LongListMultiSelector>
and in my ViewModel: 在我的ViewModel中:
FileBrowserViewModel FileBrowserViewModel
// command
public RelayCommand<File> TapOnFileCommand { get; private set; }
// constructor
public FileBrowserViewModel()
{
TapOnFileCommand = new RelayCommand<File>(
TapOnFile,
(f) => true);
}
// method
private void TapOnFile(File file)
{
if (file.IsFolder)
{
_currentFileList = file.Children;
}
}
Now the TapOnFileCommand is never executed. 现在TapOnFileCommand永远不会执行。 IntelliSense even finds the command from the XAML file.
IntelliSense甚至可以从XAML文件中找到命令。 What am I missing?
我想念什么? I'm using Mvvm Light and I would prefer not to write (to much) code behind.
我正在使用Mvvm Light,并且我不希望在后面写(太多)代码。
Here's my solution: 这是我的解决方案:
I had to move the TapOnFileCommand in a FileViewModel (elements inside the list). 我必须在FileViewModel中移动TapOnFileCommand(列表中的元素)。 The DataContext inside of the is the single item itself.
里面的DataContext是单个项目本身。 Output gave the relevant hints.
输出给出了相关提示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.