in sources/Google.Solutions.Mvvm/Binding/ToolStripMenuBindingExtensions.cs [37:118]
public static void BindItem<TModel>(
this ToolStripItem item,
TModel model,
Func<TModel, bool> isSeparator,
Expression<Func<TModel, string?>> getText,
Expression<Func<TModel, string?>> getToolTip,
Expression<Func<TModel, Image?>> getImage,
Expression<Func<TModel, Keys>> getShortcuts,
Expression<Func<TModel, bool>> isVisible,
Expression<Func<TModel, bool>> isEnabled,
Expression<Func<TModel, ToolStripItemDisplayStyle>> getStyle,
Func<TModel, ObservableCollection<TModel>> getChildren,
Action<TModel> click,
IBindingContext bindingContext)
where TModel : class, INotifyPropertyChanged
{
item.BindReadonlyProperty(
c => c.Text,
model,
getText,
bindingContext);
item.BindReadonlyProperty(
c => c.ToolTipText,
model,
getToolTip,
bindingContext);
item.BindReadonlyProperty(
c => c.Image,
model,
getImage,
bindingContext);
item.BindReadonlyProperty(
c => c.Visible,
model,
isVisible,
bindingContext);
item.BindReadonlyProperty(
c => c.Enabled,
model,
isEnabled,
bindingContext);
item.BindReadonlyProperty(
c => c.DisplayStyle,
model,
getStyle,
bindingContext);
void OnClick(object sender, EventArgs args)
=> click(model);
item.Click += OnClick;
bindingContext.OnBindingCreated(
item,
Disposable.Create(() => item.Click -= OnClick));
if (item is ToolStripMenuItem toolStripMenuItem)
{
toolStripMenuItem.BindReadonlyProperty(
c => c.ShortcutKeys,
model,
getShortcuts,
bindingContext);
var subCommands = getChildren(model);
if (subCommands != null)
{
toolStripMenuItem.DropDownItems.BindCollection(
subCommands,
isSeparator,
getText,
getToolTip,
getImage,
getShortcuts,
isVisible,
isEnabled,
getStyle,
getChildren,
click,
bindingContext);
}
}
}