Windows 10 TileText属性表现得非常奇怪

时间:2015-09-24 07:30:55

标签: c# .net visual-studio windows-phone windows-10-mobile

所以我一直在研究Win10 Universal App,并希望为它创建一些实时图块。我正在使用 NotificationExtensions 库来实现这一目标。然而,我遇到了一种超级奇怪的行为,这对我没有任何意义。基本上,我正在尝试将一些字符串分配给TileText的Text属性,并且在某些条件下它不起作用。让我举一例:

public sealed class ConnectionRequestDetailsTile : TileLayoutBase
{
     private readonly ResourceLoader m_resLoader;

     public ConnectionRequestDetailsTile(int connectionRequestCount, ResourceLoader resLoader)
     {
        if (resLoader == null)
        {
            throw new ArgumentNullException(nameof(resLoader));
        }
        m_resLoader = resLoader;

        //TileHeader.Text = m_resLoader.GetString("Connections");
        //TileStaticText.Text = m_resLoader.GetString("Requests");
        //TileData.Text = connectionRequestCount.ToString();

        TileHeader.Text = "Connections";
        TileStaticText.Text = "Requests";
        TileData.Text = connectionRequestCount.ToString();
     }

     public override async Task<TileNotification> UpdateTileAsync()
     {
        ...
     }
    .....
   }
}

public abstract class TileLayoutBase
{
    public virtual TileText TileHeader => new TileText
    {
        Style = TileTextStyle.Caption,
        Align = TileTextAlign.Left,
        MaxLines = 1
    };

    public virtual TileText TileStaticText => new TileText
    {
        Style = TileTextStyle.CaptionSubtle,
        Align = TileTextAlign.Center,
        MaxLines = 1
    };

    public virtual TileText TileData => new TileText
    {
        Style = TileTextStyle.Body,
        Align = TileTextAlign.Center,
        MaxLines = 1
    };

    public virtual TileImage TileIcon => new TileImage
    {
        Align = TileImageAlign.Left,
        RemoveMargin = true,
        Source = new TileImageSource("some_image_source")
    };

    protected virtual TileBinding CreateSmallTileBinding()
    {
        TileGroup tileGroup = new TileGroup();
        TileSubgroup tileSubGroup = new TileSubgroup { TextStacking = TileTextStacking.Center };
        ... // code to create a medium sized binding
    }

    protected virtual TileBinding CreateLargeTileBinding()
    {
        TileGroup tileGroup = new TileGroup();
        TileSubgroup tileSubGroup = new TileSubgroup { TextStacking = TileTextStacking.Center };
        ... // code to create a large tile binding
    }

    public abstract Task<TileNotification> UpdateTileAsync();
 }

这里的问题是 Text属性不做任何分配 。每当我跨过我想在子类中设置文本的行时, Text保持为空。我最初认为这必须是他们在NotificationExtensions库中实现setter的问题,所以我抓住它并反编译它。令我惊讶的是,一切似乎都很正常:

public sealed class TileText : ITileSubgroupChild, ITileAdaptiveChild
{
    private int _maxLines = int.MaxValue;
    private int _minLines = 1;

    public string Text { get; set; }

   ...
 }

如果我在基类中分配文本(我设置了所有其他常见属性,那么一切正常并且花花公子)。而且,在即时窗口中,一切似乎都很好。我怀疑它与继承有关,但我不知道它可能是什么。这是MSDN的链接,其中包含有关库的更多信息: http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/08/20/introducing-notificationsextensions-for-windows-10.aspx

一些帮助将不胜感激。用更丑陋,更不自然的代码解决这些问题是很烦人的。谢谢!

0 个答案:

没有答案