2012年4月25日 星期三
本地定時提醒 Local Notification in Windows Phone 7
參考: http://msdn.microsoft.com/en-us/library/hh202965(v=VS.92).aspx
都在 Microsoft.Phone.Scheduler 這個namespace中
除了Alarm , Remider
還有
PeriodicTask
ScheduledTask
ResourceIntensiveTask
等可供調用
動態產生圖片 Create Bitmap Dynamically in Windows Phone 7
緣起:
為了更改ShellTile的格式, 觀察到只可能從一個地方著手,
就是StandardTileData ,
這時候觀察他是繼承父類ShellTileData而來的,
所以這時候想說是否可以繼承ShellTileData 建立一個自己的ShellTileData,
從而改變ShellTile的格式.
但是這個嘗試失敗了, 至於失敗的原因..用過就知道了, 但也很有可能是小弟功力不足所致
這時候想了想 StandardTileData 裡面有兩個參數
分別是 BackgroundImage 以及BackBackgroundImage
想說是否可以動態產生圖片 讓他們來使用?
這時查到了一個叫做WriteableBitmap的東西 貌似可以使用
所以著手寫了一個小Demo
付上源代碼:
效果圖:
至於如何變成圖檔可以參考
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.extensions.savejpeg(v=vs.92).aspx
為了更改ShellTile的格式, 觀察到只可能從一個地方著手,
就是StandardTileData ,
這時候觀察他是繼承父類ShellTileData而來的,
所以這時候想說是否可以繼承ShellTileData 建立一個自己的ShellTileData,
從而改變ShellTile的格式.
但是這個嘗試失敗了, 至於失敗的原因..用過就知道了, 但也很有可能是小弟功力不足所致
這時候想了想 StandardTileData 裡面有兩個參數
分別是 BackgroundImage 以及BackBackgroundImage
想說是否可以動態產生圖片 讓他們來使用?
這時查到了一個叫做WriteableBitmap的東西 貌似可以使用
所以著手寫了一個小Demo
付上源代碼:
Canvas canvas = new Canvas ();
canvas.Width = 173;
canvas.Height = 173;
ImageBrush brush = new ImageBrush ();
BitmapImage image = new BitmapImage ();
image.UriSource = new Uri ("/MyDemos;component/Resource/haha.png", UriKind.RelativeOrAbsolute);
image.CreateOptions = BitmapCreateOptions.None;
brush.ImageSource = image;
canvas.Background = brush;
TextBlock block = new TextBlock ();
block.Width = 100;
block.Height = 100;
block.TextAlignment = TextAlignment.Center;
block.FontSize = 50;
block.Text = "Maca";
canvas.Children.Add (block);
WriteableBitmap backgroundImage = new WriteableBitmap (173, 173);
backgroundImage.Render (canvas, null);
backgroundImage.Invalidate ();
image1.Source = backgroundImage;
效果圖:
至於如何變成圖檔可以參考
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.extensions.savejpeg(v=vs.92).aspx
2012年4月9日 星期一
ApplicationBar in Windows Phone 7 -1
創建ApplicationBar
Code-behind
Xaml
Code-behind
Microsoft.Phone.Shell.ApplicationBar _ApplicationBar = new Microsoft.Phone.Shell.ApplicationBar (); Microsoft.Phone.Shell.ApplicationBarIconButton _Button = new Microsoft.Phone.Shell.ApplicationBarIconButton (new Uri ("/Icons/1.png", UriKind.Relative)); _Button.Text = "確定"; Microsoft.Phone.Shell.ApplicationBarIconButton _Button2 = new Microsoft.Phone.Shell.ApplicationBarIconButton (new Uri ("/Icons/2.png", UriKind.Relative)); _Button2.Text = "取消"; _ApplicationBar.Buttons.Add (_Button); _ApplicationBar.Buttons.Add (_Button2);
this.ApplicationBar = _ApplicationBar;
Xaml
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" x:Name="cApplicationBar" IsMenuEnabled="True">
<shell:ApplicationBarIconButton x:Name="appbar_button4" IconUri="/Icons/1.png" Text="
確定 " Click="appbar_button1_Click" />
<shell:ApplicationBarIconButton x:Name="appbar_button1" IconUri="/Icons/2.png" Text="
取消 " Click="appbar_button2_Click" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
2012年3月25日 星期日
MessageBox in Windows Phone 7
MessageBoxResult _Result = MessageBox.Show ("", "Title", MessageBoxButton.OKCancel);
效果如下圖
根據結果 可進一步操作,
if (_Result == MessageBoxResult.OK)
{
}
2012年3月22日 星期四
Convert Big5 To Unicode for windows phone 7
參考:http://forums.create.msdn.com/forums/p/73736/553266.aspx
研究一下發現wp7的library中只提供了Unicode和Utf-8兩種編碼方式,
所以如果要使用網路上big5編碼的文字就要自己轉換了 不然會變亂碼
參考了MicroStrategy的文章之後
自己再重新包裝了一個工具類
之後把網路上抓回的Stream(big5)傳進去
就可以輸出想要的Sting(unicode)了~
研究一下發現wp7的library中只提供了Unicode和Utf-8兩種編碼方式,
所以如果要使用網路上big5編碼的文字就要自己轉換了 不然會變亂碼
參考了MicroStrategy的文章之後
自己再重新包裝了一個工具類
需要先下載 這個編碼轉換的文字檔 導入專案中
之後把網路上抓回的Stream(big5)傳進去
就可以輸出想要的Sting(unicode)了~
public class Big5Util
{
private static Dictionary<int,
int> mBIG5_Unicode_MAP = new Dictionary<int, int> ();
static Big5Util ()
{
StreamResourceInfo _ResourceInfo = Application.GetResourceStream (new Uri ("MyDemos;component/Resource/BIG5.TXT",
UriKind.RelativeOrAbsolute));
StreamReader _Reader = new
StreamReader (_ResourceInfo.Stream);
String line;
while ((line = _Reader.ReadLine ()) != null)
{
if (line.StartsWith ("#"))
continue; // Comments
string[] lTokens = line.Split (new char[] { '\t' });
if (lTokens.Length < 2)
continue; // Not enough
tokens
try
{
mBIG5_Unicode_MAP.Add (int.Parse (lTokens[0].Substring
(2), NumberStyles.HexNumber), int.Parse (lTokens[1].Substring (2), NumberStyles.HexNumber));
}
catch (Exception)
{
continue; // No mapping
}
}
}
public static string ToUni (Stream
_str)
{
StringBuilder _StringBuilder = new StringBuilder
();
byte[] big5Buffer = new
byte[2];
int input;
while ((input = _str.ReadByte ()) != -1)
{
if (input > 0x81 && big5Buffer[0] == 0) //lead byte of big 5
{
big5Buffer[0] = (byte)input;
}
else if
(big5Buffer[0] != 0)
{
big5Buffer[1] = (byte)input;
int Big5Char = (big5Buffer[0] << 8) +
big5Buffer[1];
try
{
int UTF8Char =
mBIG5_Unicode_MAP[Big5Char];
_StringBuilder.Append ((char)UTF8Char);
}
catch (Exception)
{
_StringBuilder.Append ((char)mBIG5_Unicode_MAP[0xA148]);
// No mapping, use replacement character
}
big5Buffer = new byte[2];
}
else
{
_StringBuilder.Append ((char)input); // ASCII
character
}
}
return _StringBuilder.ToString ();
}
}
2012年3月20日 星期二
windows phone 7 模擬器 右邊的文字
參考:http://msdn.microsoft.com/en-us/library/ff967560(v=vs.92).aspx
| Counter | Description |
|---|---|
Composition Thread Frame Rate
|
This value refers to the rate at which the screen is updated. It also represents how often supported animations driven by a storyboard are updated. This value should be as close to 60 as possible. Application performance begins to degrade when this value is below 30. The text in this counter is red when displaying a value below 30.
|
UI Thread Frame Rate
|
This value refers to the rate at which the UI thread is running. The UI thread drives input, per-frame callbacks, and any other drawing not handled by the composition thread. The larger this value, the more responsive your application should be. Typically this value should be above 20 to provide an acceptable response time to user input. The text in this counter is red when displaying a value below 15.
|
Texture Memory Usage
|
This value represents the video memory and system memory copies of textures being used in the application. This is not a general memory counter for the application, but represents only memory that surfaces use.
|
Surface Counter
|
This value provides a raw count of the explicit surfaces being passed to the GPU for processing. The biggest contributor to this number is automatic or developer-cached elements.
|
Intermediate Surface Counter
|
This value represents the implicit surfaces generated as a result of cached surfaces. These surfaces are created in-between UI elements so that the application can accurately maintain the Z-order of elements in the UI.
|
Fill Rate Counter
|
This value represents the number of pixels being painted per frame in terms of screens. A value of 1 represents 480 x 800 pixels. The recommended value is about 2.5. The text in this counter turns red when displaying a value above 3.
|
2012年3月19日 星期一
查看APP的 Memory Usage
參考:
http://msdn.microsoft.com/en-us/library/ff941122(v=VS.92).aspx
從DeviceStatus中 可獲得一些硬體的資訊
例如: 記憶體,電源..等等
從DeviceStatus中 可獲得一些硬體的資訊
例如: 記憶體,電源..等等
總記憶體
Microsoft.Phone.Info.DeviceStatus.DeviceTotalMemory.ToString()
APP占用最多的記憶體
Microsoft.Phone.Info.DeviceStatus.ApplicationPeakMemoryUsage.ToString()
APP目前占用的記憶體
Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage.ToString()
2012年3月15日 星期四
Yield in C#
http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html
很棒的一篇文章, 利用yield 增加了變通性 讓使用者可以取得自己所需要的返回值
2012年3月13日 星期二
頁面切換動畫 TransitionService
以下是官方的Sample
有一點要特別注意就是 App.xaml.cs
RootFrame = new PhoneApplicationFrame();
要改為
RootFrame = new TransitionFrame();
不然會沒效果
如果要重複使用 可在Resource中宣告Style
<toolkit:TransitionService.NavigationInTransition>
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardIn"/>
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardIn"/>
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<toolkit:TransitionService.NavigationOutTransition>
<toolkit:NavigationOutTransition>
<toolkit:NavigationOutTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardOut"/>
</toolkit:NavigationOutTransition.Backward>
<toolkit:NavigationOutTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardOut"/>
</toolkit:NavigationOutTransition.Forward>
</toolkit:NavigationOutTransition>
</toolkit:TransitionService.NavigationOutTransition>
有一點要特別注意就是 App.xaml.cs
RootFrame = new PhoneApplicationFrame();
要改為
RootFrame = new TransitionFrame();
不然會沒效果
如果要重複使用 可在Resource中宣告Style
2012年3月12日 星期一
Z-order In WP7
無意中發現 windows phone中 調整z order的方法 數字越大越上層
1. in xaml
<Grid Name="cMaca" Canvas.ZIndex="100">
2. code-behind
cMaca.SetValue (Canvas.ZIndexProperty, 100);
1. in xaml
<Grid Name="cMaca" Canvas.ZIndex="100">
2. code-behind
cMaca.SetValue (Canvas.ZIndexProperty, 100);
2012年3月7日 星期三
改變 ApplicationBar 的 IconButton
在code-behide中調用 會產生NullReferenceException
ApplicationBarIconButton _Button = new ApplicationBarIconButton (new Uri ("/x.png", UriKind.Relative));
_Button.Click += new EventHandler (IconClick);
_Button.Text = "xxx";
ApplicationBar.Buttons.RemoveAt (0);
ApplicationBar.Buttons.Insert (0, _Button);
那要怎麼動態更改裡面的屬性呢?
其實PhoneApplicationPage中 有封裝一個ApplicationBar可以直接調用
那如果要改變裡面ApplicationBarIconButton的屬性呢?
這時候會發現ApplicationBar.Buttons不能直接Select裡面的ApplicationBarIconButton...囧
那怎麼解決呢?
方法一: 利用event中 回傳的 sender 轉型為 ApplicationBarIconButton
方法二: 利用ApplicationBar.Buttons 裡面的remove 和 insert
方法三: 直接在code-behide中定義ApplicationBar
方法二 code:
_Button.Click += new EventHandler (IconClick);
_Button.Text = "xxx";
ApplicationBar.Buttons.RemoveAt (0);
ApplicationBar.Buttons.Insert (0, _Button);
訂閱:
文章 (Atom)


