Showing posts with label Windows Phone. Show all posts
Showing posts with label Windows Phone. Show all posts

Wednesday, 30 April 2014

Srollable Tex box in windows phone 8

Design
----------
<phone:PhoneApplicationPage
    x:Class="RIMS_ParentPortal.test2"
    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"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <Grid x:Name="LayoutRoot" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="300" />
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <TextBlock Text="Scrolling TextBox sample" FontSize="40" />
     
        <ScrollViewer Grid.Row="1"
                   
                      Name="scroller">

            <TextBox Name="txtMessage"
                        TextWrapping="Wrap"
                        AcceptsReturn="True"
                        TextChanged="txtMessage_TextChanged"
                        GotFocus="txtMessage_GotFocus"
                        LostFocus="txtMessage_LostFocus"
                        Tap="txtMessage_Tap" />
         
        </ScrollViewer>
     
        <StackPanel Grid.Row="2">
            <Button Content="Button"/>

        </StackPanel>

        <Grid Grid.Row="3"  Name="pnlKeyboardPlaceholder" Visibility="Collapsed" />


    </Grid>

</phone:PhoneApplicationPage>

Code
------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;






using System.Windows.Media;
using System.Windows.Data;

namespace RIMS_ParentPortal
{
    public partial class test2 : PhoneApplicationPage
    {
        public test2()
        {
            InitializeComponent();
            Loaded+=test2_Loaded;
        }

        void test2_Loaded(object sender, RoutedEventArgs e)
        {
             //determine if HD device
            var deviceWidth = this.ActualWidth;
            var isHdDevice = (deviceWidth > 500 ? true : false);

            //the keyboard height differs between HD devices and regular ones
            if (isHdDevice)
                keyboardHeight = 540;
            else
                keyboardHeight = 336;

            //make the keyboard placeholder's height as high as
            //the anticipted keyboard height
            //this will be used to offset other controls on the page into the viewable area
            pnlKeyboardPlaceholder.Height = keyboardHeight;
        }

        double InputHeight;
        int keyboardHeight;
        double tapOffset;

        private void txtMessage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //capture the y position of where the user tapped
            //relative to the textbox
            tapOffset = e.GetPosition(txtMessage).Y - 80;
        }

        private void txtMessage_GotFocus(object sender, RoutedEventArgs e)
        {
            //reset any page movement cause by keyboard opening
            App.RootFrame.RenderTransform = new CompositeTransform();

            //make the keyboard placeholder visible
            //squishing the scrollviewer into the now smaller available screen area
            pnlKeyboardPlaceholder.Visibility = Visibility.Visible;

            //re-measure content panel, scrollviewer and it's contents
            //this is so that the scrollviewers available scrollable area is updated
            LayoutRoot.UpdateLayout();

            //scroll to the position of the click
            //(tapOffset set in Tap event - Tap event fires before this and provides tap offset)
            scroller.ScrollToVerticalOffset(tapOffset);

        }

        private void txtMessage_TextChanged(object sender, TextChangedEventArgs e)
        {
            Dispatcher.BeginInvoke(()=>
            {
                double CurrentInputHeight = txtMessage.ActualHeight;

                //after the user starts typing text, text will eventually wrap to the next line
                //this ensures the textbox height doesnt sink below the bottom of the scrollviewer
                if (CurrentInputHeight >= InputHeight)
                {
                    scroller.ScrollToVerticalOffset(scroller.VerticalOffset + CurrentInputHeight - InputHeight);
                }

                InputHeight = CurrentInputHeight;
            });
        }

        private void txtMessage_LostFocus(object sender, RoutedEventArgs e)
        {
            //hide the keyboard placeholder from screen
            //allowing the scrollviewer to re-occupy the available area again
            this.pnlKeyboardPlaceholder.Visibility = Visibility.Collapsed;

        }
    }
}


http://klingdigital.net/2013/06/scrollviewer-and-multiline-textbox-windowsphone/

Thursday, 17 April 2014

Backstack or back page in windows phone

Simply use NavigationService.GoBack(); instead of using
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
It will clear all catch automatically.
or you can use NavigationService.RemoveBackEntry(); when coming again to read second article. Use something like-
int a = NavigationService.BackStack.Count();
while (a > number) //number is stack count when comes to main page first time
{
     this.NavigationService.RemoveBackEntry();
     a = NavigationService.BackStack.Count();
}



http://stackoverflow.com/questions/17065713/windows-phone-8-back-button

Spinning bar Windows phone 8

Monday, 17 March 2014

SqlliteDb with windows phone 8

http://code.msdn.microsoft.com/wpapps/Using-Sqlite-with-WP8-52c3c671

http://blogs.msdn.com/b/andy_wigley/archive/2013/06/06/sqlite-winrt-database-programming-on-windows-phone-and-windows-8.aspx


http://chungkingmansions.com/blog/2013/08/adding-an-existing-sqlite-database-to-a-windows-phone-8-app/

Windows Phone Deploy

For Windows Phone you get a XAP file instead of an APK file.
The XAP in the ARM Release ie- ..\<Project Folder>\Bin\ARM\Release\ should be submitted to the Windows Store or Deployed to Device. Windows Phone Devices uses ARM based processors.
To generate the output-
  • First Select Release from the Solution Configuration DropBox.
  • Then go to configuration manager and change the AnyCPU field to ARM.
  • Then Build the project.
To Run on Device-
  • Open Application Deployment(a program that is installed with the Windows Phone SDK)
  • Select Target Device(Phone should be connected by USB and Unlocked. For WP 7 you need Zune.)
  • Browse and Select the XAP file in the \Bin\ARM\Release\
  • Click Deploy Button
To Run on Emulator- (use AnyCPU Build Configuration)
  • Open Application Deployment(a program that is installed with the Windows Phone SDK)
  • Select Target emulator.
  • Browse and Select the XAP file in the \Bin\x86\Release\
  • Click Deploy Button
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402565(v=vs.105).aspx

Sliding menu like Facebook

http://depblog.weblogs.us/2013/07/30/facebook-like-settings-pane-with-gestures-windows-phone/

Android and Windows Phone Shared preference

http://windowsphone.interoperabilitybridges.com/articles/android-to-wp7-chapter-6-storing-data-and-preferences