本文整理汇总了C#中System.Windows.Controls.Control.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Control.SetBinding方法的具体用法?C# Control.SetBinding怎么用?C# Control.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Control
的用法示例。
在下文中一共展示了Control.SetBinding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindProperty
public static void BindProperty(Control control, object source, string path,
DependencyProperty property, BindingMode mode)
{
var binding = new Binding(path);
binding.Source = source;
binding.Mode = mode;
control.SetBinding(property, binding);
}
示例2: SetBackgroundBinding
/// <summary>
/// Sets the background binding.
/// </summary>
/// <param name="d">The cell definition.</param>
/// <param name="c">The control.</param>
protected virtual void SetBackgroundBinding(CellDefinition d, Control c)
{
if (d.BackgroundBindingPath != null)
{
var binding = new Binding(d.BackgroundBindingPath) { Source = d.BackgroundBindingSource };
c.SetBinding(Control.BackgroundProperty, binding);
}
}
示例3: Bind
public static void Bind(Control control, Action<Control> dataContextChanged)
{
control.SetBinding(InternalDataContextProperty, new Binding());
control.SetValue(DataContextChangedProperty, dataContextChanged);
}
示例4: Attach
public void Attach(MetaAction metaAction, Control control)
{
ValidateType(control);
var existingItems = controlAction.Where(it => it.Item1 == metaAction);
var targetItem = existingItems.FirstOrDefault(it =>
{
Control c;
if (it.Item2.TryGetTarget(out c))
{
return c.Equals(control);
}
return false;
});
// already attached
if (targetItem != null)
return;
Image image = null;
if (metaAction.Icon != null)
{
image = ImageHelper.CreateImage(metaAction);
image.MaxWidth = MetaAction.ToolBarIconSize;
image.MaxHeight = MetaAction.ToolBarIconSize;
}
if (control is MenuItem)
{
var menu = (MenuItem)control;
menu.Icon = image;
menu.InputGestureText = metaAction.ShortCut;
menu.Header = metaAction.Title;
menu.ToolTip = metaAction.ToolTip;
}
if (control is ButtonBase)
{
var button = (ButtonBase)control;
button.Content = image;
button.ToolTip = metaAction.ToolTip;
if (!string.IsNullOrEmpty(metaAction.ShortCut))
{
button.ToolTip += ": " + metaAction.ShortCut;
}
}
control.SetValue(ToolTipService.ShowOnDisabledProperty, true);
// IsEnabled property
// Visibility
control.SetBinding(UIElement.VisibilityProperty,
new Binding
{
Source = metaAction,
Path = new PropertyPath("IsVisible"),
Mode = BindingMode.OneWay,
Converter = BooleanToVisibilityConverter.Instance,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
// Shortcut
if (metaAction.KeyBinding != null)
{
var window = GetWindow(control);
if (!window.InputBindings.Contains(metaAction.KeyBinding))
{
window.InputBindings.Add(metaAction.KeyBinding);
}
}
// Message.SetAttach(control, metaAction.CaliburnAction);
control.SetValue(Message.AttachProperty, metaAction.CaliburnAction);
controlAction.Add(new Tuple<MetaAction, WeakReference<Control>>(metaAction, new WeakReference<Control>(control)));
}