【问题标题】:Data binding with ListPicker issue与 ListPicker 问题的数据绑定
【发布时间】:2010-12-09 19:27:33
【问题描述】:

我正在尝试将来自 linq xml 的数据绑定到隔离存储中。数据模板(ItemTemplate 和 FullModeItemTemplate)工作正常,只显示 xml 文档中元素或属性中保存的值。

            <toolkit:ListPicker.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding BindName}" Margin="0"/>
                </DataTemplate>
            </toolkit:ListPicker.ItemTemplate>
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="16,21,0,20">
                        <TextBlock Text="{Binding BindName}" Margin="16,0,0,0" FontSize="43" FontFamily="{StaticResource PhoneFontFamilyLight}"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>

然而,虽然在列表选择器上被选中时它似乎使用了这个名称,但列表选择器持有的实际值是:

appname.pagename + namestringusedwhensetting

字符串的名称来自我假设的设置位置。我正在使用这种方法:

    public class BindingSetter
    {
        string sValue;

        public string SValueN
        {
            get { return sValue; }
            set { sValue = value; }
        }
    }

所以它正在返回:

appname.pagename + sValue

我在整个应用程序中都使用了绑定,之前没有遇到过这个问题,所以我有点难过。

提前致谢。

【问题讨论】:

  • 嗨,杰米,你没有得到太多回应;此刻听上去有点怪怪的,也可能是因为实在是怪怪的,这才更有理由把这一切解释的很清楚,好像在对孩子说一样。尽管是一个知道 XAML 和 C# 的孩子。
  • 感谢您的提示,我已经更新它以尝试更清楚地解释
  • 我不太确定出了什么问题?在您的 XAML 中,您必须使用 DataTemplates 并且两者都有绑定到 BindName 属性的 TextBlocks。现在,appname.pagename + namestringusedwhensetting 是怎么回事?在您发布 XAML 后,我完全迷失了,无法解决您的问题。
  • listpicker 模板中的文本块在隔离存储中显示来自 xml 的值,因此在表面上看起来没问题。但是,当您从列表中选择一个时,尽管由于 itemtemplate 它看起来不错,但如果您使用 .selecteditem 它会返回 appname.pagename + sValue
  • 检查我做得对...我如何检索所选项目的值?

标签: c# silverlight xaml windows-phone-7 silverlight-toolkit


【解决方案1】:

我已经设法解决了。要使用我使用的所选项目的值:

((appname.PageName.ClassUsedToBindData)(ListPickerName.SelectedItem)).String

例如。

((calculator.MainPage.CalculateBinding)(FunctionSelector.SelectedItem)).Function

希望这对像我一样苦苦挣扎的人有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    相关资源
    最近更新 更多