本文整理汇总了C#中BindingSource类的典型用法代码示例。如果您正苦于以下问题:C# BindingSource类的具体用法?C# BindingSource怎么用?C# BindingSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BindingSource类属于命名空间,在下文中一共展示了BindingSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEnumerableValueProvider
protected override IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource,
Dictionary<string, StringValues> values,
CultureInfo culture)
{
return new JQueryFormValueProvider(bindingSource, values, culture);
}
示例2: SnakeCaseQueryValueProvider
public SnakeCaseQueryValueProvider(
BindingSource bindingSource,
IReadableStringCollection values,
CultureInfo culture)
: base(bindingSource, values, culture)
{
}
示例3: AddDefaultBinding
/// <summary>
/// Adds a default binding for the action. This will also add it to the regular bindings.
/// </summary>
/// <param name="binding">The BindingSource to add.</param>
public void AddDefaultBinding( BindingSource binding )
{
if (binding == null)
{
return;
}
if (binding.BoundTo != null)
{
throw new InControlException( "Binding source is already bound to action " + binding.BoundTo.Name );
}
if (!defaultBindings.Contains( binding ))
{
defaultBindings.Add( binding );
binding.BoundTo = this;
}
if (!regularBindings.Contains( binding ))
{
regularBindings.Add( binding );
binding.BoundTo = this;
if (binding.IsValid)
{
visibleBindings.Add( binding );
}
}
}
示例4: GetChildBindingSources
private static List<BindingSourceNode> GetChildBindingSources(
IContainer container, BindingSource parent, BindingSourceNode parentNode)
{
List<BindingSourceNode> children = new List<BindingSourceNode>();
#if !WEBGUI
foreach (System.ComponentModel.Component component in container.Components)
#else
foreach (IComponent component in container.Components)
#endif
{
if (component is BindingSource)
{
BindingSource temp = component as BindingSource;
if (temp.DataSource != null && temp.DataSource.Equals(parent))
{
BindingSourceNode childNode = new BindingSourceNode(temp);
children.Add(childNode);
childNode.Children.AddRange(GetChildBindingSources(container, temp, childNode));
childNode.Parent = parentNode;
}
}
}
return children;
}
示例5: MainWindow
public MainWindow()
: base(Gtk.WindowType.Toplevel)
{
Build ();
labelError.ModifyFg (StateType.Normal, new Gdk.Color(255, 0, 0));
gridview.AutoGenerateColumns = false;
gridview.Columns.Add (new GridViewColumn () {
DataPropertyName = "ProductID", HeaderText = "ID" });
gridview.Columns.Add (new GridViewColumn () {
DataPropertyName = "ProductName", HeaderText = "Name", Width = 160 });
var colPrice = new GridViewColumn () {
DataPropertyName = "Price", HeaderText = "Price", Width = 60};
colPrice.DefaultCellStyle.Format = "C2";
gridview.Columns.Add (colPrice);
gridview.Columns.Add (new GridViewColumn () {
DataPropertyName = "Favourite", HeaderText = "Favourite"});
products = new LinqNotifiedBindingList<Product>() {};
bsrcProducts = new BindingSource (){DataSource = products};
gridview.DataSource = bsrcProducts;
entryID.DataBindings.Add (new Binding ("Text", bsrcProducts, "ProductID", true, DataSourceUpdateMode.OnPropertyChanged));
entryName.DataBindings.Add (new Binding ("Text", bsrcProducts, "ProductName", true, DataSourceUpdateMode.OnPropertyChanged));
spinPrice.DataBindings.Add (new Binding ("Value", bsrcProducts, "Price", true, DataSourceUpdateMode.OnPropertyChanged));
checkFavourite.DataBindings.Add (new Binding ("Active", bsrcProducts, "Favourite", true, DataSourceUpdateMode.OnPropertyChanged));
gridview.HeadersClickable = true;
}
示例6: BindingSourceValueProvider
/// <summary>
/// Creates a new <see cref="BindingSourceValueProvider"/>.
/// </summary>
/// <param name="bindingSource">
/// The <see cref="ModelBinding.BindingSource"/>. Must be a single-source (non-composite) with
/// <see cref="ModelBinding.BindingSource.IsGreedy"/> equal to <c>false</c>.
/// </param>
public BindingSourceValueProvider(BindingSource bindingSource)
{
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
if (bindingSource.IsGreedy)
{
var message = Resources.FormatBindingSource_CannotBeGreedy(
bindingSource.DisplayName,
nameof(BindingSourceValueProvider));
throw new ArgumentException(message, nameof(bindingSource));
}
if (bindingSource is CompositeBindingSource)
{
var message = Resources.FormatBindingSource_CannotBeComposite(
bindingSource.DisplayName,
nameof(BindingSourceValueProvider));
throw new ArgumentException(message, nameof(bindingSource));
}
BindingSource = bindingSource;
}
示例7: GetEnumerableValueProvider
protected override IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource,
IDictionary<string, string[]> values,
CultureInfo culture)
{
var backingStore = new ReadableStringCollection(values);
return new ReadableStringCollectionValueProvider(bindingSource, backingStore, culture);
}
示例8: GetEnumerableValueProvider
protected override IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource,
Dictionary<string, StringValues> values,
CultureInfo culture)
{
var backingStore = new QueryCollection(values);
return new QueryStringValueProvider(bindingSource, backingStore, culture);
}
示例9: Filter
/// <inheritdoc />
public virtual IValueProvider Filter(BindingSource bindingSource)
{
if (bindingSource.CanAcceptDataFrom(BindingSource))
{
return this;
}
else
{
return null;
}
}
示例10: ModelValidationContext
public ModelValidationContext(
BindingSource bindingSource,
[NotNull] IModelValidatorProvider validatorProvider,
[NotNull] ModelStateDictionary modelState,
[NotNull] ModelExplorer modelExplorer)
{
ModelState = modelState;
ValidatorProvider = validatorProvider;
ModelExplorer = modelExplorer;
BindingSource = bindingSource;
}
示例11: TestArrowDemo
public void TestArrowDemo()
{
Console.WriteLine("\t-- Testing arrow demo --\n");
Arrow<int, int>.func demo1 = x => x * x + 3;
// Simple arrow test - 'test' is passed through the function 'demo1' to 'result'
TestSourceObject source = new TestSourceObject();
source.value = 3;
BindingDestination<int> result = new BindingDestination<int>(0);
Arrow<int, int> testArrow = new Arrow<int, int>(demo1);
ArrowTestThing.Binding<int, int> testBinding = new ArrowTestThing.Binding<int, int>(source, "value", testArrow, result);
// Change the value of 'test' randomly and assert that 'result' changes accordingly
Console.WriteLine("Testing single binding...");
Random random = new Random();
for (int i = 0; i < 500; i++)
{
source.value = random.Next(0, 1000);
Assert.AreEqual(result, demo1(source.value));
}
Console.WriteLine("Tests passed!");
Console.WriteLine();
Arrow<int, int>.func2 demo2 = (b, h) => (b * h) / 2;
// Pair arrow test - 's1' and 's2' are treated as the breadth and height of a triangle,
// and 'result' is now bound to the area of said triangle
BindingSource<int> s1 = new BindingSource<int>(4);
BindingSource<int> s2 = new BindingSource<int>(3);
Arrow<int, int> dualArrow = new Arrow<int, int>(demo2);
PairBinding<int, int> pairBinding = new PairBinding<int, int>(s1, s2, dualArrow, result);
// Change the values of 's1' and 's2' randomly and assert that 'result' changes accordingly
Console.WriteLine("Testing double binding...");
random = new Random();
for (int i = 0; i < 500; i++)
{
s1.Value = random.Next(0, 1000);
s2.Value = random.Next(0, 1000);
Assert.AreEqual(result, demo2(s1.Value, s2.Value));
}
Console.WriteLine("Tests passed!");
Console.WriteLine();
Console.WriteLine("All tests passed successfully.\n\n");
}
示例12: InitializeBindingSourceTree
/// <summary>
/// Sets up BindingSourceNode objects for all
/// BindingSource objects related to the provided
/// root source.
/// </summary>
/// <param name="container">
/// Container for the components.
/// </param>
/// <param name="rootSource">
/// Root BindingSource object.
/// </param>
/// <returns></returns>
public static BindingSourceNode InitializeBindingSourceTree(
IContainer container, BindingSource rootSource)
{
if (rootSource == null)
throw new ApplicationException(Resources.BindingSourceNotProvided);
_rootSourceNode = new BindingSourceNode(rootSource);
_rootSourceNode.Children.AddRange(GetChildBindingSources(container, rootSource, _rootSourceNode));
return _rootSourceNode;
}
示例13: GetEnumerableValueProvider
protected override IEnumerableValueProvider GetEnumerableValueProvider(
BindingSource bindingSource,
Dictionary<string, StringValues> values,
CultureInfo culture)
{
var emptyValueProvider =
new JQueryFormValueProvider(bindingSource, new Dictionary<string, StringValues>(), culture);
var valueProvider = new JQueryFormValueProvider(bindingSource, values, culture);
return new CompositeValueProvider() { emptyValueProvider, valueProvider };
}
示例14: DataContextChangeSynchronizer
public DataContextChangeSynchronizer(BindingSource bindingSource, BindingTarget bindingTarget, ITypeConverterProvider typeConverterProvider)
{
_bindingTarget = bindingTarget;
Guard.ThrowIfNull(bindingTarget.Object, nameof(bindingTarget.Object));
Guard.ThrowIfNull(bindingTarget.Property, nameof(bindingTarget.Property));
Guard.ThrowIfNull(bindingSource.SourcePropertyPath, nameof(bindingSource.SourcePropertyPath));
Guard.ThrowIfNull(bindingSource.Source, nameof(bindingSource.Source));
Guard.ThrowIfNull(typeConverterProvider, nameof(typeConverterProvider));
_bindingEndpoint = new TargetBindingEndpoint(bindingTarget.Object, bindingTarget.Property);
_sourceEndpoint = new ObservablePropertyBranch(bindingSource.Source, bindingSource.SourcePropertyPath);
_targetPropertyTypeConverter = typeConverterProvider.GetTypeConverter(bindingTarget.Property.PropertyType);
}
示例15: Create_WhenBindingSourceIsNotFromServices_ReturnsNull
public void Create_WhenBindingSourceIsNotFromServices_ReturnsNull(BindingSource source)
{
// Arrange
var provider = new ServicesModelBinderProvider();
var context = new TestModelBinderProviderContext(typeof(IPersonService));
context.BindingInfo.BindingSource = source;
// Act
var result = provider.GetBinder(context);
// Assert
Assert.Null(result);
}