Windows Phone by default has a builtin mechanism to support copy and paste functionality, but in some case we may need to handle the copy experience explicitly.
We won't be able to paste outside a TextBox, since this is handled by the Operating System functionality. So, there is no need to handle this in code.
The Windows Phone “System.Windows” namespace exposes the Clipboard class having the following three methods to handle the Clipboard. They are:
- ContainsText()
- GetText()
- SetText(string)
ContainsText(): The ContainsText() method queries the clipboard for the presence of data in the Unicode text format and returns a bool value of true or false.
Code snippet
GetText(): The GetText() method helps to get the copied text from the clipboard. This method returns the copied Unicode text data if text is present in the clipboard, otherwise it returns an empty string.
Code snippet
Clipboard.GetText();
SetText(string text): The SetText(string text) method sets Unicode text to store/copy on the clipboard.
Code snippet
Clipboard.SetText("text to copy");
Now, here is the demo for Windows Phone 8.
Create a new Windows Phone 8 project and create one button and two textboxes as shown in the following clipboard operation.
Figure 1: PageName
XAML Code
- <phone:PhoneApplicationPage
- x:Class="ClipBoardDemo.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
- xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{StaticResource PhoneFontSizeNormal}"
- Foreground="{StaticResource PhoneForegroundBrush}"
- SupportedOrientations="Portrait" Orientation="Portrait"
- shell:SystemTray.IsVisible="True">
- <!--LayoutRoot is the root grid where all page content is placed-->
- <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="12,17,0,28">
- <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
- <TextBlock 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="12,0,12,0"></Grid>
- <Button Content="CopyToClipBoard" HorizontalAlignment="Left" Margin="107,229,0,0" Grid.Row="1" VerticalAlignment="Top" Width="260" Click="Button_Click_1"/>
- <TextBox HorizontalAlignment="Left" Height="72" TextWrapping="Wrap" VerticalAlignment="Top" Width="456" Margin="0,321,0,0" Grid.Row="1"/>
- <TextBox x:Name="clipboardTextbox" HorizontalAlignment="Left" Height="72" TextWrapping="Wrap" VerticalAlignment="Top" Width="456" Margin="2,152,0,0" Grid.Row="1"/>
- </Grid>
- </phone:PhoneApplicationPage>
C# Code
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- Clipboard.SetText(clipboardTextbox.Text.ToString());
- }

Figure 2: Enter text in the ClipBoard TextBox

Figure 3: Copy To ClipBoard

Suresh MPosted Sep 25, 2015, 12:57 AM
try this i am not sure may b it works GeoPositionPermission perm = new GeoPositionPermission(); per = GeoPositionPermission.Granted;
Murali RPosted Sep 24, 2015, 5:29 AM
Thank u for ur response...is it possible to turn on the location if it is in off condition from our application itself
Murali RPosted Sep 17, 2015, 2:14 AM
hi how to checking location is turned on/off.How to make a call for settings/loation services so that use can either enable or disable location
NitinPosted May 23, 2015, 8:52 AM
nice
Santhakumar MunuswamyPosted May 21, 2015, 2:59 PM
Thanks for nice one
Rahul Kumar SaxenaPosted May 21, 2015, 5:32 AM
Good Show..