using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace YourNamespace
{
public class BindLabel : INotifyPropertyChanged
{
private string _labelText;
private Dictionary<string,> reader = new Dictionary<string,>
{
{"info1",99}, {"info2",34}
};
public string LabelText
{
get { return _labelText; }
set
{
_labelText =
string.Format("{0} : {1}",
Convert.ToString(reader["info1"]),
Convert.ToString(reader["info2"]));
OnPropertyChanged(new PropertyChangedEventArgs("LabelText"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, e);
}
}
}
Usage:
BindLabel bindingSource = new BindLabel();
label1.DataBindings.Add("Text",bindingSource,"LabelText");
label1.Text = "IgnoreThis";
The question is: do you really want to write such code for a simple string concatenation to be handled through binding ?