尝试将字符串列表绑定到LongListMultiSelector时,应用程序崩溃

时间:2014-01-12 13:10:51

标签: c# wpf windows-phone-8

当我尝试将字符串列表绑定到LongListMultiSelector时,我遇到了一个奇怪的错误。我想要分配的值来自IsolatedStorage.GetFileNames("Path\\*");

XAML的代码: 模板

               <DataTemplate x:Key="plItemTemplate">
            <Grid Margin="{StaticResource PhoneTouchTargetOverhang}">
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu Name="conPlMgr" Opened="conPlMgr_Opened" Closed="conPlMgr_Closed">
                        <toolkit:MenuItem Name="mnuPlaylist" Header="{Binding LocalizedResources.AddToPlaylist, Source={StaticResource LocalizedStrings}}" Click="mnuPlaylist_Click"/>
                        <toolkit:MenuItem Name="mnuFav" Header="{Binding LocalizedResources.AddToFav, Source={StaticResource LocalizedStrings}}" Click="mnuFav_Click"/>
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
                <TextBlock Name="cmdPlItem" Tap="cmdPlItem_Tap" FontFamily="Segoe UI Symbol" TextWrapping="Wrap" Margin="5,0,5,5" FontSize="24"/>
            </Grid>
        </DataTemplate>

The LongListMultiSelector
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid Style="{StaticResource LongListLastItemMargin}">
                <toolkit:LongListMultiSelector
                    Name="lstPlaylists"
                    Style="{StaticResource LongListMultiselectorProps}"
                    ItemTemplate="{StaticResource plItemTemplate}"
                    ItemsSource="{Binding Instance.GetPlaylists,Source={StaticResource PlaylistManager}}"
                    IsSelectionEnabledChanged="lstPlaylists_IsSelectionEnabledChanged"/>
            </Grid>
        </Grid>

名单:

public List<string> GetPlaylists
{
    get { return isoStore.GetFileNames("Playlists\\*").ToList(); }
}

这是我收到的错误消息:

Message: Error HRESULT E_FAIL has been returned from a call to a COM component. StackTrace:  Is handled?: False e.ToString()
     

System.Windows.ApplicationUnhandledExceptionEventArgs CompleteStuff:   MS.Internal.WrappedException:错误HRESULT已返回E_FAIL   从调用COM组件。 ---&GT; System.Exception:错误HRESULT   已从调用COM组件返回E_FAIL。在   MS.Internal.XcpImports.CheckHResult(UInt32 hr)at   MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement的   element,Size availableSize)at   System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
  在System.Windows.FrameworkElement.MeasureOverride(IntPtr   nativeTarget,Double inWidth,Double inHeight,Double&amp; outWidth,   双&安培; outHeight)---内部异常堆栈跟踪结束---

我不知道这里有什么问题,值应该没有问题,它们会正确返回。我已经大肆搜索和搜索了这么多,但仍然无法找到解决方案,因为这是一个新功能的拦截器,所以令人沮丧......

更新 嗯〜我不知道,但它现在有效。 如果我这样做:<TextBlock Text={Binding} />如果我在构造函数中设置值,它就会起作用。

1 个答案:

答案 0 :(得分:0)

尝试将列表作为类的成员:

添加班级成员:

private List <string> filesList = new List<string>();

...

更改功能:

public void GetPlaylists
{
   filesList = isoStore.GetFileNames("Playlists\\*").ToList();
   LongListMultiSelectorName.itemsSource = filesList;
}

在您想要的地方调用GetPlaylists。