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.
For the binding to work, you will need to turn your field into a property like the following.
Then set your binding to your property
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