OSChina的Windows Phone客户端

@红薯 

昨天无意间发现原来OSChina还有个手机版:开源中国手机版,打开一看发现是jqurey mobile写的,最近有一直在做Windows phone 7的应用,就萌生了用webbrowser控件包装一下做个OSChina for wp客户端。昨晚就随便弄下,效果还不错。

XAML代码:

<Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="0">
            <!--<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>-->
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0">
            <phone:WebBrowser Margin="0,0,0,0" Name="webBrowser1" IsScriptEnabled="True" />
        </Grid>
    </Grid>

对应CS代码:

public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            webBrowser1.Navigate(new Uri("http://m.oschina.net/", UriKind.Absolute));
            base.OnNavigatedTo(e);
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show(OSChinaResources.Tips_ExitApp, OSChinaResources.Tips_Title, MessageBoxButton.OKCancel);
            if (result == MessageBoxResult.Cancel)
            {
                e.Cancel = true;
            }
        }
    }

效果如下:

OSChina的Windows Phone客户端_第1张图片

就这么简单。

你可能感兴趣的:(oschina,Windows&phone)