示例#1
0
        protected override void BindCore(Lifetime lifetime, DataGridView ctl, object viewModel)
        {
            var properties = TypeDescriptor.GetProperties(viewModel)
                             .OfType <PropertyDescriptor>()
                             .ToLookup(x => x.Name, x => x)
            ;

            var dataSourceProperty = properties[ctl.Name].FirstOrDefault();

            if (dataSourceProperty != null && typeof(IEnumerable).IsAssignableFrom(dataSourceProperty.PropertyType))
            {
                lifetime.Add(CreateBinding(ctl, "DataSource", viewModel, dataSourceProperty.Name));
            }

            var vmType = TypeDescriptor.GetReflectionType(viewModel);
            var selectedChangedEventHandler = vmType.GetMethod(ctl.Name + "_SelectedChanged");

            if (selectedChangedEventHandler != null)
            {
                EventHandler selectionChanged = (s, e) =>
                {
                    selectedChangedEventHandler.Invoke <object, EventArgs>(viewModel, s, e);
                };
                ctl.SelectionChanged += selectionChanged;
                lifetime.Add(Disposable.Create(() => ctl.SelectionChanged -= selectionChanged));
            }
        }
示例#2
0
        protected override void BindCore(Lifetime lifetime, TextBox ctl, object viewModel)
        {
            var properties = TypeDescriptor.GetProperties(viewModel)
                             .OfType <PropertyDescriptor>()
                             .ToLookup(x => x.Name, x => x)
            ;

            var textProperty = properties[ctl.Name].FirstOrDefault();

            if (textProperty != null && textProperty.PropertyType == typeof(string))
            {
                lifetime.Add(CreateBinding(ctl, "Text", viewModel, textProperty.Name));
            }
            else
            {
                if (ctl.Name.Contains("_"))
                {
                    var modelName = ctl.Name.Split('_')[0];
                    var modelProp = properties[modelName].FirstOrDefault();
                    if (modelProp != null)
                    {
                        lifetime.Add(CreateBinding(ctl, "Text", viewModel, ctl.Name.Replace('_', '.')));
                    }
                }
            }
        }
示例#3
0
        protected override void BindCore(Lifetime lifetime, Placeholder ctl, object viewModel)
        {
            var properties = TypeDescriptor.GetProperties(viewModel)
                             .OfType <PropertyDescriptor>()
                             .ToLookup(x => x.Name);

            var placeholderProp = properties[ctl.Name].FirstOrDefault();

            if (placeholderProp != null)
            {
                lifetime.Add(CreateBinding(ctl, "ViewModel", viewModel, placeholderProp.Name));
            }
        }
示例#4
0
        protected override void BindCore(Lifetime lifetime, Button ctl, object viewModel)
        {
            var vmType = TypeDescriptor.GetReflectionType(viewModel);

            var method = vmType.GetMethod(ctl.Name, new Type[0]);

            if (method != null)
            {
                EventHandler clicked = (s, e) => method.Invoke(viewModel, null);

                ctl.Click += clicked;

                lifetime.Add(Disposable.Create(() => ctl.Click -= clicked));
            }
        }
        public static async ValueTask <EntityScope <TEntity> > Create(
            Func <Task <TEntity> > entityCreate,
            Func <TEntity, Task> entityDelete,
            ILog log)
        {
            var lifetime = new Lifetime(log);

            try
            {
                var entity = await entityCreate();

                lifetime.Add(() => entityDelete(entity));
                var result = new EntityScope <TEntity>(entity, lifetime);
                lifetime = null;
                return(result);
            }
            finally
            {
                if (lifetime != null)
                {
                    await lifetime.DisposeAsync();
                }
            }
        }
示例#6
0
 public void Subscribe(Action <T> handler, Lifetime lf)
 {
     _handlers.Add(handler);
     lf.Add(() => _handlers.Remove(handler));
 }