silverlight - Windows Phone 7.1 可以更改外壳磁贴上的字体大小吗?

标签 silverlight windows-phone-7

我试图在动态磁贴的背面显示推文,当我将其设置为 BackContent 时,它太大了......有什么方法可以减小字体大小吗?

编辑:

克劳斯,现在我在显示图 block 时遇到了问题,并且由于您的 ImageOpened 调用的性质,我无法获得有关为什么它不工作的任何信息,我无法使用调试器单步执行它。 ..

在我的 TileGenerator 类中,这是可行的:

    public static void GenerateTestTile(string strTweet, string strScreenName, string tileTitle)
    {


            // Define the tile's address. This is where you navigate, when the tile is clicked.
            var address = "/MainPage.xaml?TileID=6";

            // Check if a tile with the same address already exists
            //var tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString() == address);
            var tile = ShellTile.ActiveTiles.First();

            // Define our tile data.
            var tileData = new StandardTileData
            {
                BackTitle = strScreenName,
                BackContent = strTweet
            };

            // If the file already exists, update it.
            if (tile != null)
            {
                tile.Update(tileData);
            }
            else
            {
                // Otherwise, create a new tile. 
                ShellTile.Create(new Uri(address, UriKind.Relative), tileData);
            }

    }

但这不会(从您的示例中获取的确切方法),它根本不会对图 block 做任何事情...

    public static void GenerateExampleTile(string timeOfDay, string temperature, Uri cloudImagePath, string tileTitle)
    {
        // Setup the font style for our tile.
        var fontFamily = new FontFamily("Segoe WP");
        var fontForeground = new SolidColorBrush(Colors.White);
        var tileSize = new Size(173, 173);

        // Create a background rectagle for a custom colour background.
        var backgroundRectangle = new Rectangle();
        backgroundRectangle.Width = tileSize.Width;
        backgroundRectangle.Height = tileSize.Height;
        backgroundRectangle.Fill = new SolidColorBrush(Colors.Blue);

        // Load our 'cloud' image.
        var source = new BitmapImage(cloudImagePath);
        source.CreateOptions = BitmapCreateOptions.None;
        source.ImageOpened += (sender, e) => // This is important. The image can't be rendered before it's loaded.
        {
            // Create our image as a control, so it can be rendered to the WriteableBitmap.
            var cloudImage = new Image();
            cloudImage.Source = source;
            cloudImage.Width = 100;
            cloudImage.Height = 64;

            // TextBlock for the time of the day.
            TextBlock timeOfDayTextBlock = new TextBlock();
            timeOfDayTextBlock.Text = timeOfDay;
            timeOfDayTextBlock.FontSize = 20;
            timeOfDayTextBlock.Foreground = fontForeground;
            timeOfDayTextBlock.FontFamily = fontFamily;

            // Temperature TextBlock.
            TextBlock temperatureTextBlock = new TextBlock();
            temperatureTextBlock.Text = temperature + '°';
            temperatureTextBlock.FontSize = 30;
            temperatureTextBlock.Foreground = fontForeground;
            temperatureTextBlock.FontFamily = fontFamily;

            // Define the filename for our tile. Take note that a tile image *must* be saved in /Shared/ShellContent
            // or otherwise it won't display.
            var tileImage = string.Format("/Shared/ShellContent/{0}.jpg", timeOfDay);

            // Define the path to the isolatedstorage, so we can load our generated tile from there.
            var isoStoreTileImage = string.Format("isostore:{0}", tileImage);

            // Open the ISF store, 
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // Create our bitmap, in our selected dimension.
                var bitmap = new WriteableBitmap((int)tileSize.Width, (int)tileSize.Height);

                // Render our background. Remember the renders are in the same order as XAML,
                // so whatever is rendered first, is rendered behind the next element.
                bitmap.Render(backgroundRectangle, new TranslateTransform());

                // Render our cloud image
                bitmap.Render(cloudImage, new TranslateTransform()
                {
                    X = 8, // Left margin offset.
                    Y = 54 // Top margin offset.
                });

                // Render the temperature text.
                bitmap.Render(temperatureTextBlock, new TranslateTransform()
                {
                    X = 124,
                    Y = 63
                });

                // Render the time of the day text.
                bitmap.Render(timeOfDayTextBlock, new TranslateTransform()
                {
                    X = 12,
                    Y = 6
                });

                // Create a stream to store our file in.
                var stream = store.CreateFile(tileImage);

                // Invalidate the bitmap to make it actually render.
                bitmap.Invalidate();

                // Save it to our stream.
                bitmap.SaveJpeg(stream, 173, 173, 0, 100);

                // Close the stream, and by that saving the file to the ISF.
                stream.Close();
            }

            // Define the tile's address. This is where you navigate, when the tile is clicked.
            var address = "/MainPage.xaml?TileID=" + timeOfDay;

            // Check if a tile with the same address already exists
            var tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString() == address);

            // Define our tile data.
            var tileData = new StandardTileData
            {
                BackgroundImage = new Uri(isoStoreTileImage, UriKind.Absolute),
                Title = tileTitle,
            };

            // If the file already exists, update it.
            if (tile != null)
            {
                tile.Update(tileData);
            }
            else
            {
                // Otherwise, create a new tile. 
                ShellTile.Create(new Uri(address, UriKind.Relative), tileData);
            }
        };
    }

两种方法都以这种方式被调用....

公共(public)类 ScheduledAgent : ScheduledTaskAgent {

    ...


    /// <summary>
    /// Agent that runs a scheduled task
    /// </summary>
    /// <param name="task">
    /// The invoked task
    /// </param>
    /// <remarks>
    /// This method is called when a periodic or resource intensive task is invoked
    /// </remarks>
    protected override void OnInvoke(ScheduledTask task)
    {
        LoadWatchList();

    }

    //WATCH LIST
    private void LoadWatchList()
    {
        if (HasConnectivity)
        {
            GetWatchListTweetsFromTwitter(CurrentWatchListID);
        }

    }

    public void GetWatchListTweetsFromTwitter(int list_id)
    {
        WebClient wcWatchListTimeline = new WebClient();
        wcWatchListTimeline.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wcWatchListTimeline_DownloadStringCompleted);
        wcWatchListTimeline.DownloadStringAsync(new System.Uri("https://api.twitter.com/1/lists/statuses.xml?per_page=1&list_id=" + list_id));
    }

    void wcWatchListTimeline_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {

        String strTweet = "content";
        String strScreenName = "title";

        if (e.Error != null)
        {
            strScreenName = "error";
            strTweet = e.Error.Message;
        }
        else
        {
            XElement tweet = XElement.Parse(e.Result);
            Tweet thisTweet = GetTweet(tweet);
            if (thisTweet != null)
            {
                strTweet = thisTweet.text;
                strScreenName = thisTweet.screen_name;
            }
        }


        // TAKEN FROM EXAMPLE FOR TESTING - NOT WORKING
        string timeOfday = "morning";
        string temperature = "99";
        string location = "San Antonio";
        Uri cloudImagePath = new Uri("Images/tweetEmpty.png", UriKind.Relative);
        Deployment.Current.Dispatcher.BeginInvoke(() => TileGenerator.GenerateExampleTile(timeOfday, temperature, cloudImagePath, "mainTile"));


        //WORKING
        //Deployment.Current.Dispatcher.BeginInvoke(() => TileGenerator.GenerateTile(strTweet, strScreenName, "mainTile"));

        NotifyComplete();
    }

    protected Tweet GetTweet(XElement Xdata)
    {

        List<Tweet> listTweets = (from tweet in Xdata.Descendants("status")
                                  select new Tweet
                                  {
                                      screen_name = tweet.Element("user").Element("screen_name").Value,
                                      text = tweet.Element("text").Value
                                  }).ToList<Tweet>();
        if (listTweets.Count > 0)
        {
            return listTweets[0];
        }
        else
        {
            return null;
        }
    }

}

最佳答案

仅通过创建自定义图像并将其用作图 block 的背景。

更新:How To: Live Tile with Scheduled Agent

关于silverlight - Windows Phone 7.1 可以更改外壳磁贴上的字体大小吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7411760/

相关文章:

windows - 从 wp7 进行 HTTPS 调用时出现 "Server not found error "

android - WCF 服务 <-> 具有快速更新的 WPF/iOS/Android 客户端通信

silverlight - MSBuild:如何在 Silverlight 构建中包含 "*.xaml"和 "*.cs"?

silverlight - Silverlight 中最大的问题是什么?

c# - 控件位于不同 Canvas /图层时的 Silverlight 碰撞检测

c# - BitmapImage.ImageOpened 未触发

windows-phone-7 - WP7 是否支持 TextTrimming= "WordEllipsis"?

.net - MEF 最佳实践是什么?

silverlight - 在 Silverlight 中使用 Rx 进行 WCF 调用不适用于 TakeUntil

c# - 如何获取网络接口(interface)的状态?