Windows Phone 創建磁貼

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="標題"/>
                <TextBlock Grid.Row="1" Grid.Column="0" Text="計數"/>
                <TextBlock Grid.Row="2" Grid.Column="0" Text="背面標題"/>
                <TextBlock Grid.Row="3" Grid.Column="0" Text="背面內容"/>
                
                <TextBox Name="txtTitle" Grid.Column="1" Grid.Row="0"/>
                <TextBox Name="txtCount" Grid.Column="1" Grid.Row="1">
                    <TextBox.InputScope>
                        <InputScope>
                            <InputScopeName NameValue="Number"/>
                        </InputScope>
                    </TextBox.InputScope>
                </TextBox>
                <TextBox Name="txtBackTitle" Grid.Column="1" Grid.Row="2"/>
                <TextBox Name="txtBackContent" Grid.Column="1" Grid.Row="3"/>
            </Grid>
            <Button Grid.Row="1" Content="創建磁貼" Click="Button_Click"/>
            <TextBlock Name="txtbTip" Text="從磁貼啓動" Grid.Row="2" Margin="0,20,0,0" Visibility="Collapsed"/>
        </Grid>
  private void Button_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Phone.Shell.StandardTileData TitleData = null;
            if(Microsoft.Phone.Shell.ShellTile.ActiveTiles.FirstOrDefault(s => s.NavigationUri.ToString().Contains("p=st")) == null ){
                try
                {
                    TitleData = new Microsoft.Phone.Shell.StandardTileData(){
                        Title = txtTitle.Text,
                        Count = Convert.ToInt32(txtCount.Text),
                        BackBackgroundImage = new Uri("favs.png", UriKind.Relative),
                        BackTitle = txtBackTitle.Text,
                        BackgroundImage = new Uri("favs.png", UriKind.Relative),
                        BackContent = txtBackContent.Text
                       
                    };
                    Microsoft.Phone.Shell.ShellTile.Create(new Uri("/MainPage.xaml?pt=st",UriKind.Relative), TitleData);
                } catch(Exception ex){
                    MessageBox.Show(ex.Message);
                }
            
            }
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if(NavigationContext.QueryString.ContainsKey("p") == true){
                this.txtbTip.Visibility = System.Windows.Visibility.Visible;
            }
        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章