【问题标题】:Separator Between Items in LongListSelector on WPWP 上 LongListSelector 中的项目之间的分隔符
【发布时间】:2014-01-05 23:42:50
【问题描述】:

我有一个绑定到联系人列表的 LongListSelector,我想添加一条小线来分隔每个联系人。

这是我的 xaml:

  <phone:LongListSelector>
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation = "Horizontal" >
                        <TextBlock  Text="{Binding informations}"  Height="120" />
                        <Image  Source="{Binding photo}"   Height="90" Width="90"  />
                        <Line Fill="Red" Height="2" />
                    </StackPanel>
                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector> 

但是项目之间没有红线,怎么加一个?

编辑:

这是否与我的 StackPanel 的方向是水平的事实有关?

【问题讨论】:

  • 您是否尝试将Width="90" 添加到Line 元素?
  • 线条使用起来很痛苦。如果它只是一个分隔符,我会使用 Rectangle

标签: c# .net xaml windows-phone


【解决方案1】:

是的,这是因为“水平”。

试试这个:

    <phone:LongListSelector>
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <StackPanel> 
                    <StackPanel Orientation = "Horizontal" >
                        <TextBlock  Text="{Binding informations}"  Height="120" />
                        <Image  Source="{Binding photo}"   Height="90" Width="90"  />
                    </StackPanel>
                    <Line Fill="Red" Height="2" />
                </StackPanel>
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>
    </phone:LongListSelector>

【讨论】:

    【解决方案2】:

    在我的情况下,上述解决方案不起作用,所以这里有一个替代解决方案:

    <phone:LongListSelector>
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <StackPanel> 
                     <StackPanel>
                         <TextBlock  Text="{Binding informations}"  Height="120" />
                         <Image  Source="{Binding photo}"   Height="90" Width="90"  />
                     </StackPanel>
                     <Rectange Fill="Red" Height="2"  width="120"/>
                </StackPanel>
             </DataTemplate>
         </phone:LongListSelector.ItemTemplate>
     </phone:LongListSelector>
    

    【讨论】: