Windows Phone开发笔记1:基础使用

接触了Win8 Metro开发和Windows Phone 7的开发已经有差不多两个月了,一直只是浅层地了解其中的一些工具使用。下面写的内容很杂很乱。

1. 模拟器参数示意图:

Frame Rate Counters with Labels

2. 在App中显示App使用的内存和峰值内存,每2秒更新一次(以MB为单位)。

    public partial class MainPage : PhoneApplicationPage
    {
        DispatcherTimer timer;
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 2);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
        void timer_Tick(object sender, EventArgs e)
        {
            try
            {
                // These are TextBlock controls that are created in the page’s XAML file.      
                MemoryTextBlock.Text = (Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage / 1048576).ToString();
                PeakMemoryTextBlock.Text = (Microsoft.Phone.Info.DeviceStatus.ApplicationPeakMemoryUsage / 1048576).ToString();
            }
            catch (Exception ex)
            {
                MemoryTextBlock.Text = ex.Message;
            }
        }
        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
        }
    }

使用时请在XAML中添加x:Name分别是MemoryTextBlock和PeakMemoryTextBlock的两个控件。

原文地址:https://www.cnblogs.com/blastmann/p/2520491.html