依赖属性在Windows Phone 8.1 App中不起作用

时间:2016-01-19 06:03:38

标签: windows-phone-8 windows-phone-8.1

我是Windows手机开发的新手,所以可能这个问题可能对你们所有专家都很奇怪。我有一个datatemplate依赖属性,在windowsphone 8.0 silverlight项目中运行正常,当我尝试在Windows Phone 8.1 App中使用相同属性时,它无法正常工作。请注意,我已经完成了在windowsphone 8.1应用程序中工作所需的所有命名空间更改。请查看下面的代码了解更多详情。 XAML代码

            <lazy:NewListBox x:Name="MainListBox" Margin="0,0,-12,0" Opacity="0.3" 
                    ItemsSource="{Binding Data}" >
            <lazy:NewListBox.LoadedItemTemplate>
            <DataTemplate>
                <Grid Height="100">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Image Source="{Binding Path=StoreImage}" Grid.Column="0" Stretch="Uniform" 
                               Width="100" Height="100" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="12,0"/>
                    <TextBlock x:Name="largeText" Grid.Column="1" Text="{Binding Path=StoreName}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Center"/>
                </Grid>
            </DataTemplate>
        </lazy:NewListBox.LoadedItemTemplate>
    </lazy:NewListBox>

C#代码

  public class NewListBox : ListBox
{
    #region LoadedItemTemplate property

    /// <summary>
    /// The "full" template to use when an item is fully loaded and visible in the list
    /// </summary>
    public DataTemplate LoadedItemTemplate
    {
        get { return (DataTemplate)GetValue(LoadedItemTemplateProperty); }
        set { SetValue(LoadedItemTemplateProperty, value); }
    }

    /// <summary>
    /// DependencyProperty that backs the <see cref="LoadedItemTemplate"/> property
    /// </summary>
    public static readonly DependencyProperty LoadedItemTemplateProperty = DependencyProperty.Register(
      "LoadedItemTemplate",
      typeof(DataTemplate),
      typeof(NewListBox),
      null);
}

我不知道我做错了什么任何帮助都表示赞赏 谢谢。 Mayank Rajpura。

0 个答案:

没有答案