Friday, June 21, 2013

[Windows Phone tips] Tip 1: Scrollable Contents

SA,

I'm going to share some tips I learned through the time I've spent with developing Windows Phone apps.

and here is the first one:-

Intro:-

sometimes you want to build a scroll-able page, for example a page that is divided into two sections (article and a comment) and you want to let the user change the size of each part smoothly.

and here is a dummy sample
 -first (the normal view)
Normal View
and then the user can  drag the black rectangle(it could be a better image with arrows :D) up and down to be like:
more space for the comments
and
The user can drag and the other content will change it's size dynamically, and can scroll both of them.

How can we do that?!

just create a new simple Windows Phone project,

We will split our ContentPanel Grid into two parts

we are going to tell it that it will have tow rows

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>


and add the top Grid:
 
<!-- Top Grid -->
<Grid Background="White" Margin="0,0,0,12" Grid.Row="0">
<!-- Scroll Viewer, to let the user scroll -->

<ScrollViewer>

<TextBlock FontSize="30" TextWrapping="Wrap" 

   Text="Auto Updated Text, This would be the main text, 
   and will change it's size according the user's action. 
   Your time is limited, <so don't waste it living someone else's life. 
   Don't let the noise of other's opinions drown out your own inner voice.
   And most important, have the courage to follow your heart and intuition." 
   Foreground="BlueViolet"/>

</ScrollViewer>

</Grid>

just TextBlock inside ScrollViewer.

and  the bottom content:-
 
<!--Bottom Grid-->
            <Grid Grid.Row="2"  x:Name="BottomGrid" Height="240" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

will split it into two rows; for the black rectangle and the bottom comment.
first part:-
 
<!-- Scroll Viewer, here where the magic happens :D 
 you can change the balck with any beatufel image with arrows(Up and Down) -->

<ScrollViewer Grid.Row="0" ManipulationDelta="ScrollViewer_ManipulationDelta_1" 
                 Height="30" Background="Black"/>

and the content will be also TextBlock inside ScrollViewer
 
<!--Bottom Content-->
<ScrollViewer Grid.Row="1" >
                 <TextBlock FontSize="28" TextWrapping="Wrap" 
                               Text="Bottom Text, This would be comment of 
                                     an article, more details,...Which 
                                     the user wanna change 
                                     the size any time. 
                                   Steve Jobs wrote this quote above ">
                    </TextBlock>
                </ScrollViewer>


How can we change the size while scrolling ?!

we listened to ManipulationDelta event to do that
and here is the code:-
 
 private void ScrollViewer_ManipulationDelta_1(object sender, 
             System.Windows.Input.ManipulationDeltaEventArgs e)
        {            
            BottomGrid.Height -= e.DeltaManipulation.Translation.Y;
        }

what happens is we change the height of the bottomGrid, and the TopGrid will take the space.


Full Source Code:
https://github.com/mostafa-elabady/ScrollableContentWP8


Have fun :D

Saturday, April 6, 2013

Git + Visual Studio 2012 + SkyDrive


SA,
--update
   this works for both Visual Studio 2010 and Visual Studio 2010

I faced a problem that I need to version my Visual Studio Projects across more than one PC.

I'm going to write how to do that easily using Git+SkyDrive

steps to do:

1- Get git

Install git from here : http://git-scm.com/download/win
Add git to path [optional]

2- Install SkyDrive App

You should use SkyDrive, DropBox, Google Drive, or any other online storage  to synchronize your projects on multiple PCs.

get SkyDrive from here: https://apps.live.com/skydrive


3- install Git Source Control Provider plug-in to Visual Studio

 Git Source Control Provider is a Visual Studio extension that integrates Git with Visual Studio.

open Visual Studio, go to Tools | Extension Manager, search online gallery for Git Source Control Provider and install it.

check this: http://gitscc.codeplex.com/wikipage?title=Installation&referringTitle=Documentation


-Install Git for Windows, or Git Extensions, or TortoiseGit
I'm using TortoiseGit.

-Add a new folder in your SkyDrive Folder

-Create your project there in your SkyDrive folder

-To create Git repository to an existing project: http://gitscc.codeplex.com/wikipage?title=Create%20Git%20Repository&referringTitle=Documentationsimply 
 -- you can do this using cmd

Finally, check this documentation: http://gitscc.codeplex.com/documentation



Have Fun :)