【问题标题】:LongListSelector Data Binding IssueLongListSelector 数据绑定问题
【发布时间】:2017-02-01 04:55:51
【问题描述】:

我是 Windows Windows Phone 编程的初学者。 我正在尝试实现 LongListSelector 以按产品显示组。

这是我的课程:

public class ProductMaster {
    public string Name { get; set; }
    public List<ProductSubMaster> Models { get; set; }
}


public class ProductSubMaster
{
    public string Name { get; set; }
    public ProductSubMasterProperty modelProperty { get; set; }
}

public class ProductSubMasterProperty{
    public string ProNo { get; set; }
    public Uri ProImage { get; set; }

}

还有我的 xaml:

 <phone:LongListSelector
                    x:Name="ProductList"
                    ItemsSource="{Binding  objProduct}"
                    Background="Transparent"
                    LayoutMode="List"
                    IsGroupingEnabled="True"
                    HideEmptyGroups ="False">
                    <phone:LongListSelector.GroupHeaderTemplate>
                        <DataTemplate>
                            <Border Background="Transparent" Padding="5">
                                <Border Background="Black" BorderBrush="Black" BorderThickness="2" Width="500" 
                                        Height="62" Margin="0,0,18,0" HorizontalAlignment="Left">
                                    <TextBlock Text="{Binding Path=[0].Name}" Foreground="White" FontSize="25" Padding="10" 
                                                FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                </Border>
                            </Border>
                        </DataTemplate>
                    </phone:LongListSelector.GroupHeaderTemplate>
                    <phone:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image x:Name="searchimg" HorizontalAlignment="Left" VerticalAlignment="Center"  Margin="10,0,0,0" Source="{Binding Path=Models.modelProperty.ProImage}" Height="100" Width="100" ></Image>
                                <TextBlock x:Name="ProductName"  Margin="20,0,0,0"  HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" TextWrapping="Wrap" Foreground="Black" Text="{Binding Path=Models.Name}" FontSize="30"></TextBlock>
                                <Image x:Name="bookmarkimg"  HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center"  Source="/Assets/Media/star.png" Height="40" Width="30" Stretch="Uniform" ></Image>
                            </StackPanel>
                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>

我正面临绑定 ItemTemplate 的问题

请帮帮我

谢谢。

【问题讨论】:

    标签: c# xaml windows-phone-8 data-binding longlistselector


    【解决方案1】:

    我在 itemtemplate 中添加了列表框解决了我的问题

    这是我更新的代码

    <phone:LongListSelector.ItemTemplate>
                                <DataTemplate>
                                <ListBox x:Name="LstFeaturesData" Visibility="Visible" ItemsSource="{Binding Path=Models}" Margin="0,0">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <Image x:Name="searchimg" HorizontalAlignment="Left" VerticalAlignment="Center"  Margin="10,0,0,0" Source="{Binding Path=modelProperty.ProImage}" Height="100" Width="100" ></Image>
                                                    <TextBlock x:Name="ProductName"  Margin="20,0,0,0"  HorizontalAlignment="Center" VerticalAlignment="Center" Width="250" TextWrapping="Wrap" Foreground="Black" Text="{Binding Path=Name}" FontSize="30"></TextBlock>
                                                    <Image x:Name="bookmarkimg"  HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center"  Source="/Assets/Media/star.png" Height="40" Width="30" Stretch="Uniform" ></Image>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </DataTemplate>
                            </phone:LongListSelector.ItemTemplate>
    

    【讨论】:

    • 您的称呼可能会导致渲染问题
    • 喜欢吗? @SwiftSharp
    猜你喜欢
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    相关资源
    最近更新 更多