Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8937411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:24:41+00:00 2026-06-15T10:24:41+00:00

I want to get a XAML specified interface on the screen so I can

  • 0

I want to get a XAML specified interface on the screen so I can learn WPF. But I do not want to start from a visual studio project which has all the wire-up already done. I wan’t the c# “hello world” equavalent of drawing a window specified in a xaml file on the screen from the “main()” function.

So how do I wire-up a XAML file to an object and draw it on the screen from a console app ? Please wire-up a simple event as well. Say a “hello world” button (specified in xaml), that when pressed makes the console print “hello world”. I’d prefer to see the delegate function in the following ways.

  1. The logic as inline c# in XAML.
  2. The logic specified in the same file as the “main()” method, as a free function (edit : oh wait c# doesn’t have free functions, well a delegate of some sort that isn’t code behind).
  3. The logic as a member function of an object, where I believe the object to be the codebehind of the XAML (assuming ofcourse this way of mapping between xaml and c# objects is possible).

Additionally : This answer shows the ui runloop taking over the main thread, is there any sugar to create a new thread for the app so it doesn’t block the callee ?

If your wondering why I am asking this question, or why I want to learn WPF this way. I want to trigger ad-hoc UI elements from within a plugin that has no other means of displaying information.


For those that find this question too vague, here is an example of xaml

<Canvas xmlns="http://schemas.microsoft.com/client/2007"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <TextBlock>Hello World!</TextBlock>
</Canvas>

The main app in this question is a console c# app, the XAML file represents a form with a single button, pressing the button prints “hello world” to the console. And I want to see the different ways of wiring up the button to my code, I do not understand how I could be clearer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:24:42+00:00Added an answer on June 15, 2026 at 10:24 am

    At the risk of being told this is not what you asked, but since it’s not clear:

    class WpfSample
    {
        [STAThread]
        public static void Main()
        {
            var window = new Window()
            {
                Title = "WPF",
                Width = 640,
                Height = 480
            };
    
            var grid = new Grid();
    
            var button = new Button()
            {
                Content = "Click Me",
                Width = 100,
                Height = 50,
    
            };
    
            grid.Children.Add(button);
            window.Content = grid;
    
            button.Click += (s, e) =>
            {
                MessageBox.Show("You clicked me");
            };
    
            window.ShowDialog();
    
        }
    }
    

    That being said, if you want plugins for your WPF application,
    doing it like this (all with code) is not the way to go.

    We define controls en such in plugins without the need for hooking it all up in code,
    we use MEF for that.

    Update
    To load the UI from some XAML you stored somewhere, you can use a ValueConverter

    public class StringToXamlValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string xaml;
            if (value != null && !String.IsNullOrWhiteSpace(value.ToString))
            {
                xaml = value.ToString();
            }
            else
            {
                xaml = Settings.Default.DefaultLayoutView;
            }
    
            var root = XamlReader.Parse(xaml);
            return root;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    You’d then set the content of some element like this:

    <ContentControl Content="{Binding Layout.View, Converter={StaticResource StringToXamlConverter}}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want get the time used for a case so I can create an
I want get as much as possible from Redis + Hiredis + libevent. I'm
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
I want to get my ComboBox in XAML to bind to my List collection
I have a circle when mousemove I can get e.GetPosition(this). But how to programmatically
I have this Xaml Code and I want to get the DataGrid dgRemplacement, I
How do I get the application's directory from my WPF application, at design time?
I want to know how you can modify properties of columns of a WPF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.