WPF startup instance

WPF project is dynamic startup instance. What does this mean ?

[STAThread]
static void Main()
{
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Test());
}

classic windows form startup function

If your project is WPF application not have program.cs , WPF have (App.xaml and App.xaml.cs) 

<Application
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="BlogTestApplication.App"
 StartupUri="Test.xaml">
 <Application.Resources>
  <!-- Resources scoped at the Application level should be defined here. -->
 </Application.Resources>
</Application>

standart App.xmal source

look StartupUri="Test.xaml" is your WPF application startup instance WPF is dynamic generate main method if you want can change

StartupUri="Test2.xaml">

Other Method

namespace BlogTestApplication
{
 /// <summary>
 /// Interaction logic for App.xaml
 /// </summary>
 public partial class App : Application
 {


 }// class end
}

App.xaml.cs standart class structure

Add new method App.xaml.cs

namespace BlogTestApplication
{
 /// <summary>
 /// Interaction logic for App.xaml
 /// </summary>
 public partial class App : Application
 {

 void Main(object sender, StartupEventArgs e)
{
  Test ttWin = new Test();
  ttWin.Show();
 }

 }// class end
}

change App.xmal attribute

<Application
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="BlogTestApplication.App"
 Startup="Main">
 <Application.Resources>
  <!-- Resources scoped at the Application level should be defined here. -->
 </Application.Resources>
</Application>

set main method  startup attribute

continue >>

asp.net routing -1

Add your project Global.asax

  • using System.Web.Routing;

protected void Application_Start(object sender, EventArgs e)
{
   RegisterRoutes(RouteTable.Routes);
}

protected void RegisterRoutes(RouteCollection routes)
{
            routes.MapPageRoute("Default",
            "index",
            "~/default.aspx");

            routes.MapPageRoute("Signup",
            "Signup",
            "~/signup.aspx");
}

continue >>

Asp.Net MVC -3

continue >>

asp.net MVC - 2 first ajax request

Page Code 

$("#btnSend").click(function () {
                $.ajax({
                    type: "POST",
                    url: "../yourcontroller/youraction",
                    data: "name=bill&surname=gates",
                    dataType: "json",
                    success: function (result) {
                     // result is json
                    }
               });// ajax end

Controller Code

public ActionResult addNameSurname(string name,string surname)
{ /* your insert */
  return Json(false);
}

continue >>

WPF Thread STA problem

When do use Wpf application  is thread  having  "The calling thread must be STA, because many UI components require this"

Sample Code:

Thread thrTest= new Thread(new ThreadStart(YourFunctionName));
           thrTest.Start();

build this code not error but runtime "The calling thread must be STA, because many UI components require this"

This Code:

Thread thrTest= new Thread(new ThreadStart(YourFunctionName));
           thrTest.SetApartmentState(ApartmentState.STA);
           thrTest.Start();

build and no error :)

continue >>
Page 1 of 5   1 2 3 4 5