English 中文(简体)
WP7 LongListSelector 具有数据约束力的项目
原标题:WP7 LongListSelector ItemsSource Databinding Issue

I am trying to implement the LongListSelector in a new WP7 application. The LongListSelector exists in a UserControl bound to an MVVMLight view model. I get the following error when I try to load the UserControl:

System.ArgumentException was unhandled Message=The parameter is incorrect. StackTrace: at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, Double d) at System.Windows.DependencyObject.SetValue(DependencyProperty property, Double d) at System.Windows.FrameworkElement.set_Width(Double value) at Microsoft.Phone.Controls.LongListSelector.GetAndAddElementFor(ItemTuple tuple) at Microsoft.Phone.Controls.LongListSelector.Balance() at Microsoft.Phone.Controls.LongListSelector.EnsureData() at Microsoft.Phone.Controls.LongListSelector.LongListSelector_Loaded(Object sender, RoutedEventArgs e) at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

我得以在我的约束力来源中将问题缩小到项目上,但我看不到问题是什么。

Here is the XAML from my UserControl:

<UserControl x:Class="BTT.PinPointTime.WinPhone.Views.TaskSelectionControl"
         xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         FontFamily="{StaticResource PhoneFontFamilyNormal}"
         FontSize="{StaticResource PhoneFontSizeNormal}"
         Foreground="{StaticResource PhoneForegroundBrush}"
         d:DesignHeight="480"
         d:DesignWidth="480"
         DataContext="{Binding Source={StaticResource Locator}, Path=TaskSelection}">

<UserControl.Resources>
    <DataTemplate x:Key="itemTemplate">
        <StackPanel Grid.Column="1"
                    VerticalAlignment="Top">
            <TextBlock Text="{Binding Name}"
                       FontSize="26"
                       Margin="12,-12,12,6" />
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="groupHeaderTemplate">
        <Border Background="YellowGreen"
                Margin="6">
            <TextBlock Text="{Binding Title}" />
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="groupItemTemplate">
        <Border Background="Pink"
                Margin="6">
            <TextBlock Text="{Binding Title}" />
        </Border>
    </DataTemplate>
</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
    <Grid x:Name="ContentPanel"
          Grid.Row="1"
          Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <toolkit:LongListSelector Grid.Row="1"
                                  Background="Red"
                                  ItemsSource="{Binding GroupedTasks}"
                                  GroupItemTemplate="{StaticResource groupItemTemplate}"
                                  ItemTemplate="{StaticResource itemTemplate}"
                                  GroupHeaderTemplate="{StaticResource groupHeaderTemplate}">
            <toolkit:LongListSelector.GroupItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel />
                </ItemsPanelTemplate>
            </toolkit:LongListSelector.GroupItemsPanel>
        </toolkit:LongListSelector>
    </Grid>
</Grid>

在这里,我使用的法典是,在我看来,将集体财产归为一种模式(被宣布为可观察的捕获和聚合物;小组:

 private void LoadData()
    {
        if (App.Database.Query<Task, Guid>().Count() > 0)
        {
            GroupedTasks.Clear();

            var tasks = (from t in App.Database.Query<Task, Guid>().ToList() select t.LazyValue.Value);

            var groupedTasks = from t in tasks
                               group t by t.FullParentString into t1
                               orderby t1.Key
                               //select new Group<Task>(t1.Key, t1);
                               select new Group<Task>(t1.Key);

            foreach (Group<Task> o in groupedTasks)
            {
                GroupedTasks.Add(o);
            }

            foreach (Group<Task> g in GroupedTasks)
            {
                var currentTasks = (from t in tasks where t.FullParentString == g.Title select t);

                foreach (Task t in currentTasks)
                {
                    g.Add(t);
                }
            }
        }

        _isDataLoaded = true;
    }

并且最后是宣布我的集团:

public class Group<T> : ObservableCollection<T>
{

    public string Title
    {
        get;
        set;
    }

    public bool HasItems
    {
        get
        {
            return Count != 0;
        }
        private set
        {
        }
    }

    public Group(string name)
    {
        this.Title = name;
    }
}

我最初是按Windows Telephone Geek的涡轮机执行这一简单数字。 然而,这给我带来了同样的错误。

我没有遇到任何约束性错误,但我看不到,这将使我能够追踪问题的根源。

最佳回答
问题回答

暂无回答




相关问题
System.Json namespace missing from Windows Phone 7

During a Mix10 presentation, the presenter (Charlie Kindel) said that when writing Silverlight based apps for WP7 you get all of Silverlight 3.0 with some of Silverlight 4.0 mixed in. Why then is ...

Will Windows Phone 7 Support Multitasking third party apps

Obviously it s early days, I do not know whether this is information that is in the public domain or not yet, but... I have trawled through some of this site - http://www.windowsphone7series.com/ but ...

Windows Series Phone 7 "Cloud"

I have been reading up on "Cloud computing" on here and still not getting it. Basically I want to develop for the WP7 http://msdn.microsoft.com/en-us/library/ff402531%28v=VS.92%29.aspx#...

Windows Phone 7 Tab Pages (page cycle)

I know.. I know, it s only a few hours old. But how the hell do you get the little page tabbing/cycle (forgot what the official name is) on the top of the page under the app title. MIX Keynotes made ...

Recording audio from the microphone in Windows Phone 7 Series

I m wondering if anyone has any code samples or links to documentation that demonstrate how to capture audio from the device s microphone on the new Windows Phone Series 7. I ve recently downloaded ...

Resources for Windows Phone 7 development [closed]

Windows Phone 7 has been unveiled and MS have announced all details of the development chain at the Mix10 conference. So this could be a good starting point/collection of online resources as they ...

热门标签