我正在尝试更改列表选择器中项目的字体大小。我使用 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# 中设置 itemsource 来填充我的列表选择器
foreach (Item i in weight)
{
sourceInput.Add(i.name);
}
}
InputSelector.ItemsSource = sourceInput;
这给我留下了一个仅包含字符串的 itemsource 列表,然后我不知道如何绑定每个项目的文本。当itemsource列表采用这种格式时,我阅读了一些关于如何做到这一点的帖子
source.Add(new Cities() { Name = "Mexico", Country = "MX", Language = "Spanish" });
this.listPicker.ItemsSource = source;
然后xaml部分是这样的
<TextBlock Text="{Binding Name}"/>
任何帮助将不胜感激 :)
更新
我找到了绑定到源项的正确绑定。
<TextBlock Text="{Binding BindsDirectlyToSource=True}"/>
看起来这就是要走的路,然后源项目被绑定到文本块