动态拼贴名称歌曲

时间:2012-08-09 19:20:03

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

我的实时图块有问题。我会在实时图块中显示我的应用程序中产生声音的歌曲名称。 我在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"/>

在App的MainPage中,出现的歌曲标题不会出现在实时图块中。 你知道这是什么问题吗? Thnx对所有人

编辑:

我在这里设置了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 = "";
        }
    }

1 个答案:

答案 0 :(得分:0)

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

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