Windows phone 7.1,Listpicker fullmodeitemtemplate绑定文本

本文关键字:fullmodeitemtemplate 绑定 文本 Listpicker phone Windows | 更新日期: 2023-09-27 18:08:17

我正在尝试更改列表选择器中项目的字体大小。我使用fullmodeitemtemplate可以更改字体大小等

问题是我不知道如何为模板中的项目绑定文本

<DataTemplate x:Name="PickerFullModeItemTemplate">
            <StackPanel Orientation="Horizontal" Margin="16 21 0 20" Background="Orange" Width="110" Height="110" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="{WHAT TO TYPE HERE?}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" FontSize="36"/>
            </StackPanel>
        </DataTemplate>

我通过在C#中设置类似的项目源来填充我的列表选择器

foreach (Item i in weight)
            {
                sourceInput.Add(i.name);
            }
        }
        InputSelector.ItemsSource = sourceInput;

这给我留下了一个只包含字符串的项目源列表,然后我不知道如何为每个项目绑定文本。我读了一些关于当项目源列表是这种格式时如何做到这一点的帖子

source.Add(new Cities() { Name = "Mexico", Country = "MX", Language = "Spanish" });
        this.listPicker.ItemsSource = source;

然后xaml部分类似于这个

<TextBlock Text="{Binding Name}"/>

任何帮助都将不胜感激:(

更新

我找到了绑定到sourceitems的正确绑定。

<TextBlock Text="{Binding BindsDirectlyToSource=True}"/>

看起来是这样的,然后源项目被绑定到文本块

Windows phone 7.1,Listpicker fullmodeitemtemplate绑定文本

您应该将Cities类型的对象添加到sourceInput集合中。

键入Text="{Binding Name}"是正确的。

很可能您的Cities类只是没有实现INotifyPropertyChanged接口。每次更新将UI元素绑定到的Name和其他属性时,都应该通知UI。

<TextBlock Text="{Binding Name}"/>

这很酷,但对于列表选择器来说,还有DisplayMemberPath属性,所以

在listpicker上添加:

DisplayMemberPath="Name">

相关文章:
  • 没有找到相关文章