Monthly Archives :

November 2012

Windows 8 Store App _ Youtube Video on Media Element 935 593 mezo

Windows 8 Store App _ Youtube Video on Media Element

Hi everyone

I want to show you to how to play a youtube video on Windows 8 Store App Media Element control. We have to use 3th part references called “MyToolKit”. MyToolKit is have a class named Youtube. That class help us to geting video and play on our control.  You can take a look in here http://mytoolkit.codeplex.com/ .

In this site they said that if you want to use this class the NuGet Package is recomended.

Ok lets start and play any video on Windows 8 Store App

First of all we have to install MyToolKit on our project. Open NuGet Package Manager from Tools->Library Package Manager -> Manage Nuget Packages for Solution

Select Online and searh MyToolKit

Thats our package we find it. We have to click on Install button and select assembly which one will use this.

MyToolKit references will add on our project after select an assembly and click OK button.  That was the diffucult side. Lets check out the simple side of our project.

I added a MediaElement control on my StoreApp xaml page and give a name property…

<Pagex:Class=”youtube.MainPage”xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:local=”using:youtube”

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″

mc:Ignorable=”d”>

<Grid Background=”{StaticResource ApplicationPageBackgroundThemeBrush}”>

<MediaElement Name=”mediaYoutube” HorizontalAlignment=”Left” Height=”522″

Margin=”152,201,0,0″ VerticalAlignment=”Top” Width=”1111″/>

<Button Name=”btnPlay” Content=”Play” HorizontalAlignment=”Left” Margin=”904,71,0,0″

VerticalAlignment=”Top”/>

<TextBox Name=”txtYoutubeID” HorizontalAlignment=”Left” Margin=”529,77,0,0″

TextWrapping=”Wrap” Text=”TextBox” VerticalAlignment=”Top” Width=”370″/>

</Grid>

</Page>

 

 

Last thing we have to do write a little code on btnPlay_Click event

private async void btnPlay_Click(object sender, RoutedEventArgs e){var url = await YouTube.GetVideoUriAsync(txtYoutubeID.Text, YouTubeQuality.Quality480P);

mediaYoutube.Source = url.Uri;

}

 

Thats it. Now we have to select a youtube video and get the video id then play on our project then watch the video.

if youtube link is http://www.youtube.com/watch?v=hNpQpjyc9C8 . this videos ID is going to be “hNpQpjyc9C8” . If we write it to our textbox we can watch this video on our Windows Store App.

Like this.

You can download the source code in here http://sdrv.ms/YfrMdG

I hope that is helpful

May the knowledge be with you

M.Zeki Osmancık

Visual Studio 2012 Update 1 Now Available 474 642 mezo

Visual Studio 2012 Update 1 Now Available

S. Somasegar today announced the availability of Visual Studio 2012 Update 1.

He said that this update is so important for developers because this isn’t just about bug fixes, though it contains quite a few of those to measurably address issues reported through Connect, UserVoice, and Windows Error Reporting.  This is also delivers a wealth of new functionality into Visual Studio 2012.  The new functionality in Update 1 primarily spans four areas of investment: Windows development, SharePoint development, agile teams, and continuous quality.

You can download Visual Studio Update 1 in  here (see “Visual Studio 2012 Update 1” under the “Additional software” section)

I hope that is helpful

May the knowledge be with you

M.Zeki Osmancık

Windows 8 Store Apps Using Localization 935 590 mezo

Windows 8 Store Apps Using Localization

Hi Friends
In this article i want to explain about localization on Windows Store Apps. If you built an application and want to make this application world wide, you have to add multi-language in your application.
So lets start the sample about using localization on Windows Store Applications.
First of all we need to add *.resw files to project. This file is string resource files and we need to add resw file for every language.

I added 3 *.resw file in my project for English German and Turkish languages in different folders with same name.

Then i modifying my *.resw files for every language:
Resources.resw file in ”en” folder

Resources.resw file in ”gr” folder

Resources.resw file in ”tr” folder

In my MainPage.xaml page i place 1 combobox 3 TextBlock and 2 Textbox.

 

<Pagex:Class=”localizationsample.MainPage”xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:local=”using:localizationsample”

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″

mc:Ignorable=”d”>

 

<Grid Background=”{StaticResource ApplicationPageBackgroundThemeBrush}”>

<TextBlock Name=”txtUserName” HorizontalAlignment=”Left” Margin=”316,304,0,0″ TextWrapping=”Wrap” Text=”User Name” VerticalAlignment=”Top” FontSize=”36″/>

<TextBlock Name=”txtPassword” HorizontalAlignment=”Left” Margin=”316,353,0,0″ TextWrapping=”Wrap” Text=”Password” VerticalAlignment=”Top” FontSize=”36″/>

<ComboBox Name=”cmbLanguage” HorizontalAlignment=”Left” Margin=”591,38,0,0″ VerticalAlignment=”Top” Width=”205″ SelectionChanged=”ComboBox_SelectionChanged_1″/>

<TextBlock HorizontalAlignment=”Left” Margin=”381,38,0,0″ TextWrapping=”Wrap” Text=”Choose Language” VerticalAlignment=”Top” FontSize=”22″/>

<TextBox HorizontalAlignment=”Left” Margin=”553,304,0,0″ TextWrapping=”Wrap” VerticalAlignment=”Top” Width=”333″/>

<TextBox HorizontalAlignment=”Left” Margin=”553,353,0,0″ TextWrapping=”Wrap” VerticalAlignment=”Top” Width=”333″/>

 

</Grid>

</Page>

 

 

 

Write very simple code for add items in combobox.

cmbLanguage.Items.Add(“en”);cmbLanguage.Items.Add(“tr”);cmbLanguage.Items.Add(“gr”);

When you select a language on combobox ,language file will change. For doing this process we must write some code on combobox selectionChanged event.

var context = new ResourceContext();var selectedLanguage = cmbLanguage.SelectedItem;if (selectedLanguage != null){var lang = new List<string>();lang.Add(selectedLanguage.ToString());

context.Languages = lang;

var resourceStringMap = ResourceManager.Current.MainResourceMap.GetSubtree(“Resources”);

this.txtUserName.Text = resourceStringMap.GetValue(“string1”, context).ValueAsString;

this.txtPassword.Text = resourceStringMap.GetValue(“string2”,context).ValueAsString;

}

ResourceContext reads the *.resw files. If we read our language files we can read ids of contents and call them where ever we want.

Our language changer is ready just test.

I hope that is helpful

May the knowledge be with you

M.Zeki Osmancık

Linq To SQL _ Insert Update Delete 570 571 mezo

Linq To SQL _ Insert Update Delete

Merhaba arkadaşlar

Bir önce ki makalede sizlere LinqToSql ile nasıl Select sorguları çalıştırabileceğiniz ile ilgili bazı bilgiler vermiştim. Bu sefer ise Insert Update ve Delete işlemleri ile ilgili bazı bilgiler vermek istiyorum. Projemiz içersine dbml dosyasını eklediğimizi varsayarak devam etmek istiyorum. Daha önceki örnekteki form tasarımına ek olarak sadece 3 Button 2 Textbox ve Label nesnelerini ekleyip bu tasarım üzerinden devam edeceğim.

Insert

Insert işlemini gerçekleştirebilmek için Kaydet butonumuzun Click olayı içersine sadece şu kodları yazmamız yeterli olacaktır.

NorthwindDataContext db = new NorthwindDataContext();
Category eklenecek = new Category();
eklenecek.CategoryName = TextBox1.Text;
eklenecek.Description = TextBox2.Text;
db.Categories.InsertOnSubmit(eklenecek);
db.SubmitChanges();
Doldur();

Bu işlemde bir dataContext örneği oluşturduktan sonra Northwind üzerine insert işlemi için gerekli olan alanları belirttiğimiz Category tipindeki nesneyi doldurup bu nesneyi tüm bilgileri ile birlikte kaydetmesini söylüyoruz.

Güncelleme ve silme işlemlerinden önce ufak bir noktaya değinmek sanırım yerinde olacaktır. SQL sorgularında yaptığımız gibi bizim burada mutlaka bir ID vermemiz gerekiyor yani güncellemek istediğimiz verinin kesin adresini yolunu belirtmeliyiz. Biliyorsunuz ki SQL kodları ile Update veya Delete komutları yazdığınızda “Where” ile ID sini belirtmezseniz tüm kayıtlar için güncelleme veya silme işlemini gerçekleştirir. Bu yüzden önce nasıl ID belirtiriz ona bakalım.  ID yazan yere 3 5 yazmayacağız tabi ki. DataGridView üzerinden bir veri seçip onu yerleştirdiğimiz Textbox ve Label lar üzerine yazdırdıktan sonra işlemlerimize devam edeceğiz.

Kayıt Seçme İşlemi

Bunun için DataGridView üzerine listelediğimiz kayıtlardan herhangi bir tanesine çift tıkladığımızda işin gerçekleşmesi için CellContentDoubleClick olayı işimizi görebilir ve içersine yazmamız gereken kodlar ise şunlar:

Bu adımdan sonra artık listelenen kayıtlar arasından birine çift tıkladığımızda tüm bilgileri text ve label nesnelerine yazılacak bizde güncelleme veya silme yaparken bu bilgilerden yararlanabiliriz.

NorthwindDataContext db = new NorthwindDataContext();
Category secilecek = db.Categories.FirstOrDefault(x => x.CategoryID == 
Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
lblID.Text = secilecek.CategoryID;
txtName.Text = secilecek.CategoryName;
txtDesc.Text = secilecek.Description;

Update

Güncelle butonumuzun Click olayına ise şu kodları eklememiz yeterli :

NorthwindDataContext db = new NorthwindDataContext();
Category guncellenen = db.Categories.FirstOrDefault(x=>x.CategoryID ==Convert.ToInt32(lblID.Text));
guncellenen.CategoryName = txtName.Text;
guncellenen.Description = txtDesc.Text;
db.SubmitChanges();
Doldur();

Burada daha önce seçip bir label üzerine yazdırdığımız ID yi kullanarak TextBox lar üzerindeki güncel verileri alıp update işlemini gerçekleştiriyoruz.

Aynı şekilde delete işlemi içinde yazmamız gereken kodlar çok basit şöyle ki :

NorthwindDataContext db = new NorthwindDataContext();
Category silinen = db.Categories.FirstOrDefault(x => x.CategoryID == int.Parse(lblID.Text));
db.Categories.DeleteOnSubmit(silinen);
db.SubmitChanges();
Doldur();

Birde burada her işlemden sonra kullandığımız datagridview içersine bilgileri dolduran Doldur metodu var onuda sizlerle paylaşayım.

db = new NorthwindDataContext();
var sonuc = from x in db.Categories
select new
{
x.CategoryID,
x.CategoryName,
x.Description
};
dataGridView1.DataSource = sonuc;

Bu kodları butonlarımızın Click olaylarına yazdıktan sonra herhangi bir hataya karşı önlem almadığımız için işlem sıramız şöyle olmalı öncelikle form açılacak ve kayıtlarımız sıralanacak , ardından bir kayıt eklemek için textboxlar doldurularak Kaydet butonuna basılacak ve Doldur metodu ile kayıtlar yeniden datagridview üzerinde görüntülenecek ardından bir kayda çift tıklayarak bilgilerini text ve label üzerine yazdıracağız ve Güncelle butonu ile güncelleme ve Sil butonu ile seçilen kaydın silinme işlemlerini gerçekleştireceğiz.

Umarım yararlı olur

Bilgiyle Kalın

M.Zeki Osmancık

 

    Join our Newsletter

    We'll send you newsletters with news, tips & tricks. No spams here.