【问题标题】:Live tile name song活瓷砖名称歌曲
【发布时间】:2012-08-09 19:20:02
【问题描述】:

我遇到了动态磁贴问题。我会在动态磁贴中显示我的应用程序中生成声音的歌曲名称。 我在 MainPage.xaml.cs 中使用过:

public MainPage()
    {
        InitializeComponent();
        // Application Tile is always the first Tile, even if it is not pinned to Start.
        ShellTile TileToFind = ShellTile.ActiveTiles.First();

        // Application should always be found
        if (TileToFind != null)
        {
            // if Count was not entered, then assume a value of 0

            // set the properties to update for the Application Tile
            // Empty strings for the text values and URIs will result in the property being cleared.
            StandardTileData NewTileData = new StandardTileData
            {
                Title = "MyNameApp",
                BackgroundImage = new Uri("Red.jpg", UriKind.Relative),

                BackTitle = "Zzz...",
                BackBackgroundImage = new Uri("Green.jpg", UriKind.Relative),
                BackContent = txtCurrentTrack.Text <<HERE MY PROBLEM
            };

            // Update the Application Tile
            TileToFind.Update(NewTileData);
        }


    }

在 MainPage.xaml 中:

<TextBlock x:Name="txtCurrentTrack" Height="75" HorizontalAlignment="Center" Margin="12,193,0,0" VerticalAlignment="Top" Width="438" TextWrapping="Wrap"/>

在应用程序的 MainPage 中,歌曲的标题出现,而不是在动态磁贴中不出现。 你知道是什么问题吗? 谢谢大家

编辑:

我在这里设置了 txtcurrentTrack.Text(在 MainPage.xaml.cs 中):

void Instance_PlayStateChanged(object sender, EventArgs e)
    {
        switch (BackgroundAudioPlayer.Instance.PlayerState)
        {
            case PlayState.Playing:
                RelaxTB.Content = "pause";
                break;

            case PlayState.Paused:
            case PlayState.Stopped:
                RelaxTB.Content = "play";
                break;
        }
        if (null != BackgroundAudioPlayer.Instance.Track)
        {
            txtCurrentTrack.Text = BackgroundAudioPlayer.Instance.Track.Title;
        }
    }
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
        {
            RelaxTB.Content = "Pause";
            txtCurrentTrack.Text = BackgroundAudioPlayer.Instance.Track.Title;

        }
        else
        {
            RelaxTB.Content = "Play";
            txtCurrentTrack.Text = "";
        }
    }

【问题讨论】:

  • 您是否尝试过调试以确保设置了 StandardTileData 的 BackContent 属性?
  • 是的。如果我在 BackContent 中写一个字符串,例如 BackContent="example",它就可以工作。相反,如果我写 txtCurrentTrack.Text 它不起作用。但是,我编辑了显示设置 txtCurrentTrack.Text 位置的代码

标签: c# silverlight windows-phone-7 live-tile


【解决方案1】:

txtCurrentTrack 上的 Text 属性似乎没有在您更新磁贴数据时设置。因此,您只能将 BackContent 属性设置为 null。

You need to update the tile explicitly each time you change txtCurrentTrack.Text - 在 Instance_PlayStateChanged 和 OnNavigatedTo 方法中。

【讨论】:

  • 如 TriggerPin 所示,您只是在 MainPage 的构造函数中设置 BackContent 和 tile 数据。当 txtCurrentTrack.Text 更新时,您也没有做任何事情来更新动态磁贴。
猜你喜欢
  • 1970-01-01
  • 2018-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多