我在Windows Phone 7中查找ListPicker
控件的代码示例,遇到了这个(http://www.c-sharpcorner.com/uploadfile/f397b9/using-listpicker-in-windows-phone-7/)
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Name="lpkItemTemplate">
<TextBlock Text="{Binding Country}" />
</DataTemplate>
<DataTemplate x:Name="lpkFullItemTemplate">
<TextBlock Text="{Binding Country}" />
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
.
.
.
<toolkit:ListPicker FullModeItemTemplate="{Binding lpkFullItemTemplate}"
Grid.Row="5" ItemTemplate="{Binding lpkItemTemplate}"
x:Name="lpkCountry"/>
在这个例子中,ListPicker DataTemplates
是在PhoneApplicationPage.Resources
字典中定义的,属性FullModeItemTemplate
和ItemTemplate
是使用{Binding}
扩展设置的,我对WPF有一点了解,所以我不希望代码能正常运行,但当我尝试它时,它运行得很好,所以我在WPF中尝试了一个等效的例子,但没有运行
<Window.Resources>
<Style TargetType="Button" x:Name="btnComic">
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="Foreground" Value="Red"/>
</Style>
</Window.Resources>
<Grid>
<Button Style="{Binding btnComic}" Content="Test"/>
</Grid>
silverlight和WPF中的绑定是否如此不同,以至于相同的语法在一个平台上有效,但在另一个平台中无效?或者我只是错过了什么?
WPF和WPSilverlight有些不同,但绑定的工作方式大致相同。链接处的代码是胡言乱语。(请参阅此处以获取正确的示例。)
可能发生的情况是"FullModeItemTemplate"one_answers"ItemTemplate"绑定失败(请检查VS中的Output窗口进行确认)。请注意,DataTemplates
也是无意义的(这些项是字符串,而不是具有"Country"属性的对象)。运行该代码可能是因为ListPicker将在没有设置项模板的情况下将项显示为字符串。