Vasu Ashok
Vasu Ashok

Reputation: 1413

how to code Windows phone 7 UI only programatically (in .cs file)without using designer

I'm newbie for Windows phone 7 development.

Usually the User interface Design is done with a Designer and Drag & Drop. But In my project I have to code all user interface programmatically, that is manually write design controls in .Cs file instead of .xaml file.

Is it possible? I have tried googling it, I haven't found any tutorial or documentation yet.

Could someone please help me to start my process.refer some documentation or books

Thanks

Upvotes: 2

Views: 4380

Answers (5)

Jan Slodicka
Jan Slodicka

Reputation: 1515

Generally I don't like the designer and try to avoid it as much as possible. I find writing Xaml easier.

But I also try to avoid the use of Xaml because:

  • Performance: the C# code is definitely faster
  • Programming style: I hate when the related code is scattered over several files. It's not only my C# code, but also hidden auto-generated code (sometimes containing unnecessary constructs).
  • Debugging: Xaml allows for more bugs (e.g. incorrect spelling), Xaml bugs are more difficult to localize

Having said that, I have to disagree with Stuart: Certain things cannot be done in C#, you need to do them in Xaml. For example:

  • Visual states: You cannot set readonly property VisualStateGroup.Name in C#, but you can use x:Name attribute in Xaml.

  • UserControl.Content is protected (for SVL3 and thus also for WP7), but Xaml bypasses this limitation

Etc. (There are more such special things.)

Upvotes: 0

Stuart
Stuart

Reputation: 66882

I definitely think you can do everything without XAML if you want to.

The basic approach should be to create a basic app with App.xaml and an almost empty Page.xaml. After this you should be able to dynamically add controls to meet your needs.

The majority of this work is quite straight-forward

  • creating controls, setting properties, adding event handlers are all easy.
  • The more awkward things will be things like producing animations, visual states, styles and databindings - the XAML syntax for these is quite convenient compared to the C#
  • Also, if you need multiple pages, then using navigation is also a bit more awkward - the NavigationService is currently built around XAML-based pages.

In iron7, I've written lots of single page apps without using XAML. All the code is in IronRuby rather than C#. As a developer, I think you should be able to follow most of them - take a look at these examples on script.iron7.com:

To run these scripts just download iron7free from the marketplace. To convert them back into C# is mainly a case of removing some "_" characters, modifying some capitalization and turning def's into C# methods.

Note - for clarification, I am not recommending you write your app in Ruby - it's just that these are the only examples I have of writing an app in code instead of XAML.

Upvotes: 4

Steve Chadbourne
Steve Chadbourne

Reputation: 6953

You have to create a basic xaml page first with at least a stack panel on it.

Then you can add controls to your stack panel like this

TextBox textbox = new Textbox();
textbox.Text = "TEST";
PageStackPanel.Children.Add(textBox);

Upvotes: 2

Matt Evans
Matt Evans

Reputation: 7585

Well its the Silverlight framework. You can code it by hand using XAML (eXtensible Application Markup Language)

Charles Petzold is writing a book on Windows Phone 7 programming, you can download it free here:

http://www.charlespetzold.com/

Upvotes: 0

rkg
rkg

Reputation: 5719

You do have drag and drop ability for the Windows Phone 7 development. Download the Visual Studio for Windows Phone 7 and try the samples. http://www.microsoft.com/express/Phone/

Here is a tutorial for the starters: http://blogs.msdn.com/b/somasegar/archive/2010/03/15/introducing-windows-phone-7-development-tools.aspx

Upvotes: 0

Related Questions