本文整理汇总了C#中PropertyItem.CreateBinding方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyItem.CreateBinding方法的具体用法?C# PropertyItem.CreateBinding怎么用?C# PropertyItem.CreateBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyItem
的用法示例。
在下文中一共展示了PropertyItem.CreateBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDefaultControl
/// <summary>
/// Creates the default control.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreateDefaultControl(PropertyItem property)
{
// TextBox is the default control
var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
var c = new TextBoxEx
{
AcceptsReturn = property.AcceptsReturn,
MaxLength = property.MaxLength,
IsReadOnly = property.IsReadOnly,
TextWrapping = property.TextWrapping,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
VerticalContentAlignment = property.AcceptsReturn ? VerticalAlignment.Top : VerticalAlignment.Center
};
if (property.FontFamily != null)
{
c.FontFamily = new FontFamily(property.FontFamily);
}
if (!double.IsNaN(property.FontSize))
{
c.FontSize = property.FontSize;
}
if (property.IsReadOnly)
{
// c.Opacity = 0.8;
c.Foreground = Brushes.RoyalBlue;
}
var binding = property.CreateBinding(trigger);
if (property.ActualPropertyType != typeof(string) && IsNullable(property.ActualPropertyType))
{
// Empty values should set the source to null
// Set the value that is used in the target when the value of the source is null.
binding.TargetNullValue = string.Empty;
}
c.SetBinding(TextBox.TextProperty, binding);
return c;
}
示例2: CreateSpinControl
/// <summary>
/// Creates the spin control.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreateSpinControl(PropertyItem property)
{
var tb = new TextBoxEx
{
IsReadOnly = property.IsReadOnly,
BorderThickness = new Thickness(0),
HorizontalContentAlignment = ConvertHorizontalAlignment(property.HorizontalAlignment),
VerticalContentAlignment = VerticalAlignment.Center
};
tb.SetBinding(TextBox.TextProperty, property.CreateBinding());
var c = new SpinControl
{
Maximum = property.SpinMaximum,
Minimum = property.SpinMinimum,
SmallChange = property.SpinSmallChange,
LargeChange = property.SpinLargeChange,
Content = tb
};
// Note: Do not apply the converter to the SpinControl
c.SetBinding(SpinControl.ValueProperty, property.CreateBinding(UpdateSourceTrigger.Default, false));
return c;
}
示例3: CreateBoolControl
/// <summary>
/// Creates the bool control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateBoolControl(PropertyItem property)
{
var c = new CheckBox
{
VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left
};
c.SetBinding(ToggleButton.IsCheckedProperty, property.CreateBinding());
return c;
}
示例4: CreateHtmlControl
/// <summary>
/// Creates the HTML control.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreateHtmlControl(PropertyItem property)
{
var c = new WebBrowser();
c.SetBinding(WebBrowserBehavior.NavigateToStringProperty, property.CreateBinding());
return c;
}
示例5: CreatePasswordControl
/// <summary>
/// Creates the password control.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreatePasswordControl(PropertyItem property)
{
var c = new PasswordBox();
PasswordHelper.SetAttach(c, true);
c.SetBinding(PasswordHelper.PasswordProperty, property.CreateBinding());
return c;
}
示例6: CreateEnumControl
/// <summary>
/// Creates the select control.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreateEnumControl(
PropertyItem property, PropertyControlFactoryOptions options)
{
var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
var values = Enum.GetValues(enumType);
var style = property.SelectorStyle;
if (style == DataAnnotations.SelectorStyle.Auto)
{
style = values.Length > options.EnumAsRadioButtonsLimit
? DataAnnotations.SelectorStyle.ComboBox
: DataAnnotations.SelectorStyle.RadioButtons;
}
switch (style)
{
case DataAnnotations.SelectorStyle.RadioButtons:
{
var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType };
c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
return c;
}
case DataAnnotations.SelectorStyle.ComboBox:
{
var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) };
c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
return c;
}
case DataAnnotations.SelectorStyle.ListBox:
{
var c = new ListBox { ItemsSource = Enum.GetValues(enumType) };
c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
return c;
}
default:
return null;
}
}
示例7: CreateFontFamilyControl
/// <summary>
/// Creates the font family control.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreateFontFamilyControl(PropertyItem property)
{
var c = new ComboBox { ItemsSource = GetFontFamilies() };
if (property.PreviewFonts)
{
var dt = new DataTemplate { DataType = typeof(ComboBox) };
var factory = new FrameworkElementFactory(typeof(TextBlock));
factory.SetValue(TextBlock.FontSizeProperty, property.FontSize);
factory.SetValue(TextBlock.FontWeightProperty, FontWeight.FromOpenTypeWeight(property.FontWeight));
factory.SetBinding(TextBlock.TextProperty, new Binding());
factory.SetBinding(TextBlock.FontFamilyProperty, new Binding { Converter = FontFamilyConverter });
dt.VisualTree = factory;
c.ItemTemplate = dt;
}
var binding = property.CreateBinding();
if (property.ActualPropertyType == typeof(string))
{
binding.Converter = FontFamilyConverter;
}
c.SetBinding(Selector.SelectedValueProperty, binding);
return c;
}
示例8: CreateGridControl
/// <summary>
/// Creates the grid control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateGridControl(PropertyItem property)
{
var c = new SimpleGrid { CanDelete = property.ListCanRemove, CanInsert = property.ListCanAdd };
var glc = new GridLengthConverter();
foreach (var ca in property.Columns.OrderBy(cd => cd.ColumnIndex))
{
var cd = new ColumnDefinition
{
DataField = ca.PropertyName,
Header = ca.Header,
FormatString = ca.FormatString,
Width = (GridLength)glc.ConvertFromInvariantString(ca.Width)
};
switch (ca.Alignment.ToString().ToUpper())
{
case "L":
cd.HorizontalAlignment = HorizontalAlignment.Left;
break;
case "R":
cd.HorizontalAlignment = HorizontalAlignment.Right;
break;
default:
cd.HorizontalAlignment = HorizontalAlignment.Center;
break;
}
c.ColumnDefinitions.Add(cd);
}
c.SetBinding(SimpleGrid.ContentProperty, property.CreateBinding());
return c;
}
示例9: CreateSpinControl
/// <summary>
/// Creates the spin control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateSpinControl(PropertyItem property)
{
var tb = new TextBox
{
BorderThickness = new Thickness(0), HorizontalContentAlignment = HorizontalAlignment.Right
};
tb.SetBinding(TextBox.TextProperty, property.CreateBinding());
var c = new SpinControl
{
Maximum = property.SpinMaximum,
Minimum = property.SpinMinimum,
SmallChange = property.SpinSmallChange,
LargeChange = property.SpinLargeChange,
Content = tb
};
c.SetBinding(SpinControl.ValueProperty, property.CreateBinding());
return c;
}
示例10: CreateEnumControl
/// <summary>
/// Creates the enum control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <param name="options">
/// The options.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateEnumControl(PropertyItem property, PropertyControlFactoryOptions options)
{
var isRadioButton = true;
var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
var values = Enum.GetValues(enumType);
if (values.Length > options.EnumAsRadioButtonsLimit && !property.UseRadioButtons)
{
isRadioButton = false;
}
if (isRadioButton)
{
var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType };
c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
return c;
}
else
{
var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) };
c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
return c;
}
}
示例11: CreateFilePathControl
/// <summary>
/// Creates the file path control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateFilePathControl(PropertyItem property)
{
var c = new FilePicker
{
Filter = property.FilePathFilter,
DefaultExtension = property.FilePathDefaultExtension,
UseOpenDialog = property.IsFileOpenDialog,
FileDialogService = this.FileDialogService
};
if (property.RelativePathDescriptor != null)
{
c.SetBinding(FilePicker.BasePathProperty, new Binding(property.RelativePathDescriptor.Name));
}
if (property.FilterDescriptor != null)
{
c.SetBinding(FilePicker.FilterProperty, new Binding(property.FilterDescriptor.Name));
}
c.SetBinding(FilePicker.FilePathProperty, property.CreateBinding());
return c;
}
示例12: CreateDirectoryPathControl
/// <summary>
/// Creates the directory path control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateDirectoryPathControl(PropertyItem property)
{
var c = new DirectoryPicker { FolderBrowserDialogService = this.FolderBrowserDialogService };
c.SetBinding(DirectoryPicker.DirectoryProperty, property.CreateBinding());
return c;
}
示例13: CreateDefaultControl
/// <summary>
/// Creates the default control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateDefaultControl(PropertyItem property)
{
// TextBox is the default control
var trigger = property.AutoUpdateText ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default;
var c = new TextBox
{
AcceptsReturn = property.AcceptsReturn,
MaxLength = property.MaxLength,
IsReadOnly = property.Descriptor.IsReadOnly,
TextWrapping = property.TextWrapping,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto
};
c.SetBinding(TextBox.TextProperty, property.CreateBinding(trigger));
return c;
}
示例14: CreateComboBoxControl
/// <summary>
/// Creates the combo box control.
/// </summary>
/// <param name="property">
/// The property.
/// </param>
/// <returns>
/// The control.
/// </returns>
protected FrameworkElement CreateComboBoxControl(PropertyItem property)
{
var c = new ComboBox { IsEditable = property.IsEditable };
c.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(property.ItemsSourceDescriptor.Name));
c.SetBinding(
property.IsEditable ? ComboBox.TextProperty : Selector.SelectedValueProperty, property.CreateBinding());
return c;
}
示例15: CreateDictionaryControl
/// <summary>
/// Creates a dictionary control.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>
/// The control.
/// </returns>
protected virtual FrameworkElement CreateDictionaryControl(PropertyItem property)
{
// todo
var c = new ComboBox();
c.SetBinding(ItemsControl.ItemsSourceProperty, property.CreateBinding());
return c;
}