简体   繁体   English

转换/数据绑定,样式文本块 WP7

[英]Convert/Data binding, style textblock WP7

   {
      "body": "testtt",
      "from_id": 37917395,
    },
    {
      "body": "hiii",
      "from_id": 124769733,
    },

I parse this response and need that messages from id "37917395" will be on left side of textblock, and messages from id "124769733" will be on right side.Like this:我解析此响应并需要来自 id "37917395" 的消息将位于文本块的左侧,来自 id "124769733" 的消息将位于右侧。像这样:

testtt测试

     hiii

The messages may be not in order.Like this:消息可能不按顺序排列。像这样:

testtt测试

This also me这也是我

 hiii

I want to develop something like this:我想开发这样的东西:

短信查看

I think I need to use Converter.我想我需要使用转换器。 Please help me with algorithm.请帮我算法。

What I've already have.我已经拥有的。在此处输入图像描述

I don't think a converter alone will be enough.我认为仅靠转换器是不够的。

Converters work on one value at a time and you need your example control to have knowledge of what the previous value (above it) was in order to change the alignment/grouping.转换器一次处理一个值,您需要您的示例控件了解前一个值(在其上方)是什么,以便更改对齐/分组。

Best you change the type of data you are binding to.最好更改要绑定的数据类型。 Parse the data first into a structure more suited to the display requirements.首先将数据解析为更适合显示要求的结构。 Include say a Left/Right alignment value as one of the properties.包括一个左/右 alignment 值作为属性之一。 A converter would then be useful for converting that flag into an alignment.然后,转换器可用于将该标志转换为 alignment。

Might be time for you to look at ViewModels:)可能是你看看 ViewModel 的时候了:)

You'll need to determine if the from_id indicates if the message should be on the left or the right.您需要确定from_id是否指示消息应该在左侧还是右侧。 You'll then need to combine this with whatever method you are using to control whehter display is on the left or the right.然后,您需要将其与您用来控制显示在左侧还是右侧的任何方法相结合。

I'd assume you are making your own control to display the messages.我假设您正在制作自己的控件来显示消息。 I'd also assume that you have a property to indicate if it displays on the left or right of the screen.我还假设您有一个属性来指示它是显示在屏幕的左侧还是右侧。 You should bind the from_id to this property and then use the converter to do the determining of if which side the message should be.您应该将from_id绑定到此属性,然后使用转换器来确定消息是否应该在哪一侧。

if your data are put in a listbox, you need to use a DataTemplateSelector in the ItemTemplate of your listbox, with a first DataTemplate align left, and the other one align right.如果您的数据放在列表框中,则需要在列表框的 ItemTemplate 中使用 DataTemplateSelector,第一个 DataTemplate 左对齐,另一个右对齐。 Just search a tutorial for DataTemplateSelector on WP7, it's exactly what you need只需在 WP7 上搜索 DataTemplateSelector 的教程,这正是您所需要的

@wsevendays If each comment/record has a integer primary key then you could %2 that value (find the remainder when divided by two), which will either be 0 or 1 and use that to set a property to align the data in the UI to the left or right hand side. @wsevendays 如果每条评论/记录都有一个 integer 主键,那么您可以 %2 该值(除以 2 时找到余数),该值将是 0 或 1,并使用它来设置属性以对齐 UI 中的数据到左侧或右侧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM