StringFormat 是否可以与 this.DataContext 一起使用
我通过 this.DataContext = SellerList; 将 TextBlock 与代码隐藏中的集合绑定在一起 输出是正确的,但是当我应用 StringFormat 时,我看不到结果。以下是xaml页面上TextBlock的代码
<TextBlock Name="dateDTKey" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Text="{Binding Path=Date, StringFormat={}{0:dd-MM-yyyy}}"
Style="{StaticResource textStyleTextBlock}"/>
I am binding a TextBlock with a collection in code-behind via this.DataContext = SellerList;
The output is correct but when i apply StringFormat, i see no result. Following is the code for TextBlock on xaml page
<TextBlock Name="dateDTKey" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Text="{Binding Path=Date, StringFormat={}{0:dd-MM-yyyy}}"
Style="{StaticResource textStyleTextBlock}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
绑定的源是一个字符串,如果
detailsSellerListingTemplate
是您应该使用{StaticResourcedetailsSellerListingTemplate}
的资源。此外,TextBlock 不需要 DataContext 即可使此 Binding 工作,因为它使用 Source。如果
DetailsSeller
看起来与此类似,这将起作用您谈到了一个集合,但我看不出它如何与绑定相匹配,所以也许我误解了问题中的某些内容
The source for the Binding is a string, if
detailsSellerListingTemplate
is a resource you should use{StaticResource detailsSellerListingTemplate}
. Also, the TextBlock doesn't need a DataContext for this Binding to work since it's using Source.This will work if
DetailsSeller
looks similar to thisYou talked about a collection but I can't see how that fits with the binding, so maybe I missunderstood something in the question
我认为这是因为你的字符串格式中有很多大括号。试试这个:
I am thinking its because you have way to many braces in your string format. try this: