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

  • Home
  • SEARCH
  • 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 6694895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:09:20+00:00 2026-05-26T06:09:20+00:00

This is a very simple question: I have a string defined in my C#

  • 0

This is a very simple question: I have a string defined in my C# class and I would like it to be the content of a XAML button. That’s it. What can I put in the ????. I know this is basic WPF… I will keep looking for an answer. Thanks in advance.

My XAML

<Window x:Class="BarScore.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        >

    <StackPanel>
        <Button Name="Start" Content="???" Height="25" Width="100"
           Margin="20" />
    </StackPanel>
</Window>

My C# code

using System;
using System.Windows;
using System.Windows.Controls;

namespace BarScore
{
    public partial class MainWindow : Window
    {
        public string BUTTON_NAME_STR = "START";

        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

PS: I know I can go to the code and write:

Start.Content = BUTTON_NAME_STR;

but I would like it to be from XAML to C# and not the other way around, if possible.

  • 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-05-26T06:09:21+00:00Added an answer on May 26, 2026 at 6:09 am

    For the binding to work, you will need to turn your field into a property like the following.

    using System;
    using System.Windows;
    using System.Windows.Controls;
    
    namespace BarScore
    {
        public partial class MainWindow : Window
        {
            private string _BUTTON_NAME_STR = "START";
            public string BUTTON_NAME_STR
            {
               get
               {
                    return _BUTTON_NAME_STR;
               }
               set
               {
                    _BUTTON_NAME_STR = value;
               }
            }
    
            public MainWindow()
            {
                InitializeComponent();
                Start.DataContext=this;
            }
        }
    }
    

    Then set your binding to your property

    <StackPanel>
        <Button Name="Start" Content="{Binding BUTTON_NAME_STR}"
           Height="25" Width="100"
           Margin="20" />
    </StackPanel>
    

    Some more links on it :

    http://blogs.msdn.com/b/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx

    http://msdn.microsoft.com/en-us/magazine/cc163299.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem like a very simple question, but I have been struggling with
I have a simple question. I have a model that looks like this: public
I have a very simple question: How can I make this code more simple
This may seem a very silly question. Consider this: I have a simple Boolean
This is a very simple question, but I can't seem to find something about
I'm sure this is a very simple question, but embarrassed to say I can't
I have a very simple question, and I shouldn't be hung up on this,
Ok this is more of general technology/approach question. We have a very simple web
i have a very simple question , i'm new to rhino this is my
very simple question, i have this: (only a part of the complete rss file)

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.