With a good grasp of . NET development, it's possible to come up with extremely cool apps for new high end Windows 8 Phones
Wednesday, January 22, 2014
Monday, January 20, 2014
Assume you created a button and you'd like to call several functions when this button is pressed. To do that, we need to add event handlers to the button's click. This way, we don't have to write a common task which might be shared by several buttons many many times
public MainPage()
{
InitializeComponent();
BT1.Content = " Program started";
BT1.Click += BackgroundCOlorChanged;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
i++;
if (i % 2 == 1)
{
Tb1.Text = "You just hovered";
}
else
{
Tb1.Text = "You hovered again";
}
}
private void BackgroundCOlorChanged(object sender, RoutedEventArgs e)
{
Tb2.Text = "ABCDEF";
}
public MainPage()
{
InitializeComponent();
BT1.Content = " Program started";
BT1.Click += BackgroundCOlorChanged;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
i++;
if (i % 2 == 1)
{
Tb1.Text = "You just hovered";
}
else
{
Tb1.Text = "You hovered again";
}
}
private void BackgroundCOlorChanged(object sender, RoutedEventArgs e)
{
Tb2.Text = "ABCDEF";
}
Posted on 9:14 PM by Erdem
I am trying to figure out what good stackpanel can bring to the table. Haven't been able to do much with it yet. I figured, you can define some stack panels on top of each other and define them as levels as seen below. I am not sure where to go from there but this looks like an OK way to align text etc
<phone:PhoneApplicationPage
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"
xmlns:es="clr-namespace:Microsoft.Expression.Shapes;assembly=Microsoft.Expression.Drawing"
x:Class="BasicLayout03StackP01.MainPage"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid HorizontalAlignment="Left" Height="768" VerticalAlignment="Top" Width="480">
<Grid HorizontalAlignment="Left" Height="470" Margin="0,10,0,0" VerticalAlignment="Top" Width="480" Background="#FFBD6464">
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Background="#FF4C8BCB">
<TextBlock TextWrapping="Wrap" Text="TextBlock" Margin="10,0,10,0"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,50,0,0" Background="#FF6DAA15">
<TextBlock TextWrapping="Wrap" Text="TextBlock"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,100,0,0" Background="#FFC32424">
<TextBlock TextWrapping="Wrap" Text="TextBlock"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,150,0,0" Background="#FF092729"/>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,200,0,0" Background="#FF4DAE8F"/>
</Grid>
<Grid HorizontalAlignment="Left" Height="288" Margin="0,480,0,0" VerticalAlignment="Top" Width="480" Background="#FF03135B"/>
</Grid>
</phone:PhoneApplicationPage>
<phone:PhoneApplicationPage
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"
xmlns:es="clr-namespace:Microsoft.Expression.Shapes;assembly=Microsoft.Expression.Drawing"
x:Class="BasicLayout03StackP01.MainPage"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid HorizontalAlignment="Left" Height="768" VerticalAlignment="Top" Width="480">
<Grid HorizontalAlignment="Left" Height="470" Margin="0,10,0,0" VerticalAlignment="Top" Width="480" Background="#FFBD6464">
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Background="#FF4C8BCB">
<TextBlock TextWrapping="Wrap" Text="TextBlock" Margin="10,0,10,0"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,50,0,0" Background="#FF6DAA15">
<TextBlock TextWrapping="Wrap" Text="TextBlock"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,100,0,0" Background="#FFC32424">
<TextBlock TextWrapping="Wrap" Text="TextBlock"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,150,0,0" Background="#FF092729"/>
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="480" Margin="0,200,0,0" Background="#FF4DAE8F"/>
</Grid>
<Grid HorizontalAlignment="Left" Height="288" Margin="0,480,0,0" VerticalAlignment="Top" Width="480" Background="#FF03135B"/>
</Grid>
</phone:PhoneApplicationPage>
Posted on 8:46 PM by Erdem
Sunday, January 19, 2014
With this app, it's possible to add rectangular shapes to each cell.
<phone:PhoneApplicationPage
x:Class="BasicLayout02.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.Pho
ne"
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="Colorful Cells" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" HorizontalAlignment="Center"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="114" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock>1</TextBlock>
<TextBlock Grid.Column="1">2</TextBlock>
<TextBlock Grid.Column="2">3</TextBlock>
<TextBlock Grid.Column="3">4</TextBlock>
<TextBlock Grid.Row="1">5</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1">6</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2">7</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="3">8</TextBlock>
<TextBlock Grid.Row="2">9</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="1">10</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="2">11</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="3">12</TextBlock>
<TextBlock Grid.Row="3">13</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="1">14</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="2">15</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="3">16</TextBlock>
<Rectangle Grid.Row="0" Grid.Column="0" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="0" Grid.Column="1" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="0" Grid.Column="2" Width="23" Fill="Red"></Rectangle>
<Rectangle Grid.Row="0" Grid.Column="3" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="0" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="1" Width="23" Fill="Red"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="2" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="3" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="0" Width="23" Fill="Red"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="1" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="2" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="3" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="0" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="1" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="2" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="3" Width="23" Fill="Red"></Rectangle>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
<phone:PhoneApplicationPage
x:Class="BasicLayout02.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.Pho
ne"
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="Colorful Cells" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" HorizontalAlignment="Center"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="114" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock>1</TextBlock>
<TextBlock Grid.Column="1">2</TextBlock>
<TextBlock Grid.Column="2">3</TextBlock>
<TextBlock Grid.Column="3">4</TextBlock>
<TextBlock Grid.Row="1">5</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1">6</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2">7</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="3">8</TextBlock>
<TextBlock Grid.Row="2">9</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="1">10</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="2">11</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="3">12</TextBlock>
<TextBlock Grid.Row="3">13</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="1">14</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="2">15</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="3">16</TextBlock>
<Rectangle Grid.Row="0" Grid.Column="0" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="0" Grid.Column="1" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="0" Grid.Column="2" Width="23" Fill="Red"></Rectangle>
<Rectangle Grid.Row="0" Grid.Column="3" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="0" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="1" Width="23" Fill="Red"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="2" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="3" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="0" Width="23" Fill="Red"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="1" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="2" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="2" Grid.Column="3" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="0" Width="23" Fill="Blue"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="1" Width="23" Fill="White"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="2" Width="23" Fill="Yellow"></Rectangle>
<Rectangle Grid.Row="3" Grid.Column="3" Width="23" Fill="Red"></Rectangle>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
Posted on 8:56 PM by Erdem
Adding rows and columns are best done in XAML, rather than Blend. See the example below where a grid is dis-sectioned and each cell has a number
<phone:PhoneApplicationPage
x:Class="BasicLayout02.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.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock>1</TextBlock>
<TextBlock Grid.Column="1">2</TextBlock>
<TextBlock Grid.Column="2">3</TextBlock>
<TextBlock Grid.Column="3">4</TextBlock>
<TextBlock Grid.Row="1">5</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1">6</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2">7</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="3">8</TextBlock>
<TextBlock Grid.Row="2">9</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="1">10</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="2">11</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="3">12</TextBlock>
<TextBlock Grid.Row="3">13</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="1">14</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="2">15</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="3">16</TextBlock>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
Here's the output
Posted on 8:25 PM by Erdem
Grids are used to organize other controls. Rows and columns can be defined so that other controls can locate themselves in the location they need to be. Example below shows a simple maxinpage.xml that uses grids and row controls a little bit
<phone:PhoneApplicationPage
x:Class="BasicLayout01.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">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<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>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/> <!-- When used * means th of avalable space-->
<RowDefinition Height="2*"/> <!-- Here it is 2/6 of available space -->
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<Rectangle Fill="Red" Grid.Row="0" />
<Rectangle Fill="Blue" Grid.Row="1" />
<Rectangle Fill="Green" Grid.Row="2" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>
The output screen looks like that
<phone:PhoneApplicationPage
x:Class="BasicLayout01.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">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<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>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/> <!-- When used * means th of avalable space-->
<RowDefinition Height="2*"/> <!-- Here it is 2/6 of available space -->
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<Rectangle Fill="Red" Grid.Row="0" />
<Rectangle Fill="Blue" Grid.Row="1" />
<Rectangle Fill="Green" Grid.Row="2" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>
The output screen looks like that
Posted on 7:58 PM by Erdem
Saturday, January 18, 2014
Data binding is extreme effective way of connecting XAML to C#. In this example, I show how to make the simplest data binding possible.
First, create a dummy windows phone app.
Second, add a text box. The only thing we need to add to this text box is data binding feature. To do that, we open XAML editor and add the following:
Text="{Binding Name}"
to our textbox, that's it.
Third, in our C# code, we need to add a property to connect with the Texbox. Below is my example.
namespace PhoneApp2
{
public class Student
{
public string Name { get; set; }
public string Lastname;
}
public partial class MainPage : PhoneApplicationPage
{
private Student _firstStudent;
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
_firstStudent = new Student()
{
Name = "Joseph Doors"
};
ContentPanel.DataContext = _firstStudent;
}
}
}
This should produce an output similar to this:

First, create a dummy windows phone app.
Second, add a text box. The only thing we need to add to this text box is data binding feature. To do that, we open XAML editor and add the following:
Text="{Binding Name}"
to our textbox, that's it.
Third, in our C# code, we need to add a property to connect with the Texbox. Below is my example.
namespace PhoneApp2
{
public class Student
{
public string Name { get; set; }
public string Lastname;
}
public partial class MainPage : PhoneApplicationPage
{
private Student _firstStudent;
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
_firstStudent = new Student()
{
Name = "Joseph Doors"
};
ContentPanel.DataContext = _firstStudent;
}
}
}
This should produce an output similar to this:
Posted on 8:23 AM by Erdem
Sunday, January 12, 2014
# Define a generic class
# Define a variable and constructor
namespace GenericsConsole1
{
class Student<T>
{
public T justAnInput;
public Student(T constructorInput)
{ Console.WriteLine(constructorInput);}
}
class Program
{
static void Main(string[] args)
{
Student<string> Gavur;
Gavur = new Student<string>("AAA");
Gavur.justAnInput = "Test me";
Console.ReadKey();
}
}
}}
# Define a variable and constructor
namespace GenericsConsole1
{
class Student<T>
{
public T justAnInput;
public Student(T constructorInput)
{ Console.WriteLine(constructorInput);}
}
class Program
{
static void Main(string[] args)
{
Student<string> Gavur;
Gavur = new Student<string>("AAA");
Gavur.justAnInput = "Test me";
Console.ReadKey();
}
}
}}
Posted on 5:20 PM by Erdem
Zaman zaman variable lerin type ini degistirmek gerekebilir. Mesela double alan bir method var, ve buna int32 pass etmek istiyoruz. Boyle durumlarda variable'in type ini degistirmeye casting denir.
Eger int long'a veya double'a cevireleekse, burada veri kaybetme riski olmadigindan, implicit bir sekilde yani c# compiler tarafindan bu is halledilir.
Eger double int'e cevirelecekse burada veri kaybetme riski oldugundan, explicit bir sekilde yani user tarafindan variable tipi degistirmek gerekir. Buna da casting denir ve casting operatoru kullanmak icap eder.
http://msdn.microsoft.com/en-us/library/ms173105.aspx
Eger int long'a veya double'a cevireleekse, burada veri kaybetme riski olmadigindan, implicit bir sekilde yani c# compiler tarafindan bu is halledilir.
Eger double int'e cevirelecekse burada veri kaybetme riski oldugundan, explicit bir sekilde yani user tarafindan variable tipi degistirmek gerekir. Buna da casting denir ve casting operatoru kullanmak icap eder.
http://msdn.microsoft.com/en-us/library/ms173105.aspx
Posted on 5:05 PM by Erdem
Generics bir class ve method tipi. Bu tipin ne avantaji var, islevi nedir.. Bunlari anlamak epeyi vakit alabilir.
Basit bir cerceve, application uzerinden ornek verirsek, Generics kullanmayarak bir liste olusturalim:
Basit bir cerceve, application uzerinden ornek verirsek, Generics kullanmayarak bir liste olusturalim:
System.Collections.ArrayList list = new System.Collections.ArrayList(); // Add an integer to the list. list.Add(3); // Add a string to the list. This will compile, but may cause an error later. list.Add("It is raining in Redmond.");
Burada "list" objesi, hem String hem int elemanlar icermekte. Bunu saglayabilmesi icin bir upcasting olmasi lazim cunku hem int hem string ayni kefeye koyabilmek icin bunlari ayni cinse dondurmesi lazim. Burada int ve string object sinifina upcast edilliyor. Burada bir sorun yok ama kullanici int ve string den haberdar olmayarak, icinden cikilmayacak bir hata yapabilir. Bunu engellemek icin ihtiyacimiz olan, definition esnasinda direk tek bir type a cast edilmesi. Burda da Generics class devreye su sekilde giriyor:
// The .NET Framework 2.0 way to create a list List<int> list1 = new List<int>(); // No boxing, no casting: list1.Add(3);Bu listenin elemanlari integer olmak zorunda dolasiyla casting kaynakli bir hata cikmasi soz konusu degil. Iste Generics basitce bu ise yariyor..
Posted on 4:59 PM by Erdem
Subscribe to:
Posts (Atom)
Categories
Blog Archive
-
▼
2014
(22)
-
▼
January
(22)
- What is Asynchronous Programming?
- Quality C# (C sharp) Code Examples
- Windows phone emulator not connected to internet
- Using ListBoxes with Buttons and Adding Many Buttons
- Data Binding with a Slider
- Data Binding with Radio Buttons and Two Way Binding
- Data Binding to Control Multiple Objects - Part 1
- High End Windows 8 Phones
- Adding Event Handlers to Controls
- Stack Panel Experiments Part 1
- Using Grid in Windows Phone 8 Development Part 3
- Using Grid in Windows Phone 8 Development Part 2
- Using Grid in Windows Phone 8 Development Part 1
- Simplest Data Binding for Windows Phone 8
- Very simple code using generics
- Casting nedir?
- Generics nedir? Basitce ne ise yariyor
- Windows Store trends, interesting data showing wha...
- How to submit your app to windows app store
- Boxing and Unboxing
- Using Indexers
- Setting logo, publisher name, tile image and some ...
-
▼
January
(22)
Popular Posts
Powered by Blogger.





