To have a RibbonTextBox automatically update your data when the user updates the ribbon textbox and vice-versa, you can use the RibbonTextBox.TextValueBinding to establish a 2-way databinding. Here is a sample code :
public class ManufacturerData
: System.ComponentModel.INotifyPropertyChanged
{
private string manufacturerName;
public ManufacturerData() { }
public ManufacturerData(String manufacturer)
{
manufacturerName = manufacturer;
}
public String ManufacturerProperty
{
get { return manufacturerName; }
set
{
manufacturerName = value;
OnPropertyChanged("ManufacturerProperty" );
}
}
public event
System.ComponentModel.
PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string info)
{
System.ComponentModel.PropertyChangedEventHandler
handler = PropertyChanged;
if (handler != null)
{
handler(this , new System.ComponentModel.
PropertyChangedEventArgs(info));
}
}
}
public class Commands
{
public static ManufacturerData _data
= new ManufacturerData("Autodesk" );
public static bool _added = false ;
[CommandMethod("RTB" )]
static public void RibbonTextBoxMethod()
{
if (!_added)
{
Autodesk.Windows.RibbonControl rc
= Autodesk.Windows.ComponentManager.Ribbon;
Autodesk.Windows.RibbonTab rt = null;
foreach (Autodesk.Windows.RibbonTab tab
in rc.Tabs)
{
if (tab.AutomationName.Equals("Add-ins" ))
{
rt = tab;
break ;
}
}
if (rt == null)
return ;
Autodesk.Windows.RibbonPanelSource rps
= new Autodesk.Windows.RibbonPanelSource();
rps.Title = "MyPanel" ;
Autodesk.Windows.RibbonPanel rp
= new Autodesk.Windows.RibbonPanel();
rp.Source = rps;
rt.Panels.Add(rp);
Autodesk.Windows.RibbonTextBox rtb
= new Autodesk.Windows.RibbonTextBox();
rtb.Id = "MyRTB" ;
rtb.Text = "Manufacturer" ;
rtb.ShowText = true ;
rps.Items.Add(rtb);
rt.IsActive = true ;
System.Windows.Data.Binding myBinding
= new System.Windows.Data.Binding
("ManufacturerProperty" );
myBinding.Source = _data;
myBinding.Mode
= System.Windows.Data.BindingMode.TwoWay;
rtb.TextValueBinding = myBinding;
_added = true ;
}
}
}