아래 코드는 TransformToVisual을 이용해서 현재 페이지 기준으로 특정 Element의 위치를 구하는 코드입니다.
// Obtain transform information based off root element
GeneralTransform gt = element.TransformToVisual(Application.Current.RootVisual);
// Find the four corners of the element
Point topLeft = gt.Transform(new Point(0, 0));
Point topRight = gt.Transform(new Point(element.RenderSize.Width, 0));
Point bottomLeft = gt.Transform(new Point(0, element.RenderSize.Height));
Point bottomRight = gt.Transform(new Point(element.RenderSize.Width, element.RenderSize.Height));
Popup클래스에 Orientation을 지원하기 위해서는 2가지 방법이 있는데 첫번째 방법은 Popup을 xaml코드를 이용해서 visual tree에 넣는 방법이고, 두번째 방법은 Behind Code에서 RotateTransform을 이용해서 직접 회전시켜 주는 방법입니다.
첫번째 방법인 xaml을 이용하는 방법은 Panel 컨트롤 등 아래에 Popup을 넣는 방법으로 이렇게 해주면 Orientation이 알아서 적용되고, Popup이 띄워질 위치의 기준은 Panel컨트롤이 됩니다.
아래는 xaml코드의 일부로 Popup안에 Button을 하나 올려놓고, 해당 Popup은 ContentPanel(Grid control) 기준으로 50*50 위치에 팝업되어서 나타납니다.
두번째 방법인 RotateTransform을 이용하는 방법은 Landscape 상태일떄 Popup을 각각 90, -90도 돌려주고, 그에 맞게 VerticalOffset과 HorizontalOffset을 음수 좌표로 변경해줘야합니다.
아래는 Behind code의 일부로 Popup을 전체화면 기준으로 300*300에 팝업되도록 할 때 Orientation이 LandscapeLeft일때 Popup을 설정하는 코드입니다. RotateTransform을 이용해서 90도로 변경하고, VerticalOffset을 음수좌표로 변경하는 코드로 이때 480은 (Landscape기준)화면의 세로 길이입니다.
Windows Phone 7의 Orientation을 PortraitOrLandscape로 설정했다면 현재의 Orientation을 얻어오거나 Orientation이 변경되는 시점을 알아야할 때가 있습니다.
현재의 Orientation을 얻어오려면 PhoneApplicationPage.Orientation Property를 사용하면 되고, Orientation이 변경되는 시점을 알고 싶으면 PhoneApplicationPage.OrientationChanged Event를 등록해서 사용하면 됩니다.
아래는 샘플코드이고 둘다 PageOrientation enum값을 사용합니다.
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
//Add EventHandler
this.OrientationChanged += new EventHandler(MainPage_OrientationChanged);
}
void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
PageOrientation orientation = e.Orientation;
//Check current orientation
if ((orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
{
// Portrait
}
else
{
// Landscape
}
}
PageOrientation GetCurrentOrientation()
{
return this.Orientation;
}
}
Windows Phone 7의 Theme는 Dark/Light 2개의 Background를 설정할 수 있고, 10개의 Accent color를 설정할 수 있습니다.
아래는 위의 값들을 얻어오는 방법과 각 값의 ARGB 색상정보입니다.
//Get background color
Color themeBackColor = (Color)Application.Current.Resources["PhoneBackgroundColor"];
//Get foreground color
Color themeForeColor = (Color)Application.Current.Resources["PhoneForegroundColor"];
//Get accent color
Color accentColor = (Color)Application.Current.Resources["PhoneAccentColor"];