[英]WP8: LongListMultiSelector Tap Item Trigger MVVM
關於LongListMultiSelector(Windows Phone 8 Toolkit)的另一個問題。 在LongListMultiSelector中點擊單個項目時,我想啟動命令。
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>
在我的ViewModel中:
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;
}
}
現在TapOnFileCommand永遠不會執行。 IntelliSense甚至可以從XAML文件中找到命令。 我想念什么? 我正在使用Mvvm Light,並且我不希望在后面寫(太多)代碼。
這是我的解決方案:
我必須在FileViewModel中移動TapOnFileCommand(列表中的元素)。 里面的DataContext是單個項目本身。 輸出給出了相關提示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.