If you mean you want to dynamically add buttons via binding the following approach may help you.
At first you add a ItemsControl
section to your xaml defining an ItemTemplate.
<ItemsControl ItemsSource="{Binding DynamicControlObjects}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Text}"
ToolTip="{Binding Tooltip}"
IsEnabled="{Binding IsEnabled}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
The DynamicControlObjects
is just a simple IList<T>
where T
is a class containing the properties you want to bind.
For example what I am using in this case is my class DynamicControlHelper
:
// ...
using Microsoft.Practices.Prism.ViewModel;
// ...
public class DynamicControlHelper : NotificationObject
{
#region Backing Fields
private string _text;
private bool _isEnabled;
private string _tooltip;
#endregion Backing Fields
#region Properties
public string Text
{
get
{
return this._text;
}
set
{
if (!string.Equals(this._text, value))
{
this._text = value;
this.RaisePropertyChanged(nameof(this.Text));
}
}
}
public bool IsEnabled
{
get
{
return this._isEnabled;
}
set
{
if (this._isEnabled != value)
{
this._isEnabled = value;
this.RaisePropertyChanged(nameof(IsEnabled));
}
}
}
// ...
public string Tooltip
{
get
{
return this._tooltip;
}
set
{
if (!string.Equals(this._tooltip, value))
{
this._tooltip = value;
this.RaisePropertyChanged(nameof(this.Tooltip));
}
}
}
#endregion Properties
}
When I needed this approach the first time. The answer from H.B. leads me to my solution.