在我的文本块前面添加标签
我有一个从网络服务获取数据的列表,但数据需要一个标签或另一个文本块来说明该数据是什么。有没有办法将其插入到此列表框中?
所以我想要的结果是
“HIN Number:” - 然后显示绑定到 HINNumber 的文本块
“类别字母:” - 然后显示绑定到categoryLetter的文本块
“类别1:” - 然后显示绑定到category1的文本块
“类别 2:” - 然后显示绑定到类别 2 的文本块
“类别 3:” - 然后显示绑定到类别 3 的文本块
我想我可以将另一个文本块对齐到匹配的数据绑定文本块旁边,但有些值为空,所以列表框的位置不断变化,所以这是行不通的。
<ListBox x:Name="HINList" Margin="0,300,-12,0" ItemsSource="{Binding Details}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding HINNumber}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding CategoryLetter}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding Category1}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding Category2}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding Category3}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have a list which gets data from a web service but the data needs a label or another textblock to say what that data is. Is there a way of inserting this within this listbox?
so my desired outcome would be
"HIN Number:" - then display the textblock which is bound to HINNumber
"Category Letter:" - then display the textblock which is bound to categoryLetter
"Category 1:" - then display the textblockwhich is bound to category1
"Category 2:" - then display the textblockwhich is bound to category2
"Category 3:" - then display the textblockwhich is bound to category3
I thought I could just align another textblock up next to the matching databound textblock but some values are null and so the position of the listbox is constantly changing so this wouldnt work.
<ListBox x:Name="HINList" Margin="0,300,-12,0" ItemsSource="{Binding Details}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding HINNumber}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding CategoryLetter}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding Category1}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding Category2}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding Category3}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您是否希望标签位于每个文本块的左侧或上方。
上面更简单 - 只需在堆栈面板中使用额外的文本块:
如果您希望标签位于右侧,请使用 2 列网格来布局控件。
It depends if you want the label to the left of or above each textblock.
Above is easier - just use extra textblocks in the stackpanel:
If you want the labels to the right, use a 2 column grid to layout the controls.