public static void Main() { var mainViewModel = new MainViewModel(); var button = new Button() { Command = mainViewModel.PostCommand, TextContent = "Post" }; var headerInput = new TextInput(); headerInput.PlaceHolder = "Header"; SimpleBinding.Create(mainViewModel, "HeaderInput", headerInput, "Value"); var contentInput = new TextInput(); contentInput.PlaceHolder = "Content"; SimpleBinding.Create(mainViewModel, "ContentInput", contentInput, "Value"); var list = new ItemsControl <Post>(new VBox()) { // "postItemTemplate" is a reference to an element defined in MainPage.html ItemElementFactory = new TemplateElementFactory <Post>("postItemTemplate") }; SimpleBinding.Create(list, "ItemsSource", mainViewModel, "Posts"); var box = new VBox { Content = { headerInput, contentInput, button, list } }; Element.GetById("target").AppendChild(box); }
protected Control MakeCheckBoxWidget(PalasoDataObject target, Field field) { FlagState boxState = target.GetOrCreateProperty <FlagState>(field.FieldName); CheckBoxControl control = new CheckBoxControl(boxState.Value, field.DisplayName, field.FieldName); SimpleBinding <bool> binding = new SimpleBinding <bool>(boxState, control); binding.CurrentItemChanged += _detailList.OnBinding_ChangeOfWhichItemIsInFocus; return(control); }
protected Control MakeOptionWidget(PalasoDataObject target, Field field) { OptionRef optionRefTarget = target.GetOrCreateProperty <OptionRef>(field.FieldName); OptionsList list = WeSayWordsProject.Project.GetOptionsList(field, false); IWritingSystemDefinition preferredWritingSystem = _viewTemplate.GetDefaultWritingSystemForField(field.FieldName); SingleOptionControl control = new SingleOptionControl(optionRefTarget, list, field.FieldName, preferredWritingSystem, WeSayWordsProject.Project.ServiceLocator); SimpleBinding <string> binding = new SimpleBinding <string>(optionRefTarget, control); binding.CurrentItemChanged += _detailList.OnBinding_ChangeOfWhichItemIsInFocus; return(control); }
protected override Control MakePictureWidget(PalasoDataObject target, Field field, DetailList detailList) { PictureRef pictureRef = target.GetOrCreateProperty <PictureRef>(field.FieldName); PictureControl control = _serviceProvider.GetService(typeof(PictureControl)) as PictureControl; control.SearchTermProvider = new SenseSearchTermProvider(target as LexSense); if (!String.IsNullOrEmpty(pictureRef.Value)) { control.Value = pictureRef.Value; } SimpleBinding <string> binding = new SimpleBinding <string>(pictureRef, control); binding.CurrentItemChanged += detailList.OnBinding_ChangeOfWhichItemIsInFocus; return(control); }
private AutoCompleteWithCreationBox <T, string> CreatePicker <T>(LexRelation relation) where T : class { var picker = new AutoCompleteWithCreationBox <T, string> ( CommonEnumerations.VisibilitySetting.Visible, WeSayWordsProject.Project.ServiceLocator ); picker.Box.Tag = relation; // switch (type.TargetType) // { // case LexRelationType.TargetTypes.Entry: // //picker.Box.Items = Project.WeSayWordsProject.Project // break; // case LexRelationType.TargetTypes.Sense: // break; // default: // break; // } picker.Box.WritingSystem = GetWritingSystemFromField(); picker.Box.PopupWidth = 200; //review: picker.Box.MinimumSize = new Size(40, 10); if (picker.Box.SelectedItem == null && !string.IsNullOrEmpty(relation.Key)) { picker.Box.Text = relation.Key; // picker.Box.ShowRedSquiggle = true; } _binding = new SimpleBinding <string>(relation, picker); //for underlinging the relation in the preview pane _binding.CurrentItemChanged += _focusDelegate; return(picker); }
public UnbindResult( WindowElementBinder binder, SimpleBinding simpleBinding ) { _binder = binder; _simpleBinding = simpleBinding; }
bool Comparer( SerializableBinding sb, SimpleBinding s ) { return (sb.Target == s.Target.Name && sb.Origin == s.Origin.Name && sb.Position == s.Position) || (sb.Target == s.Origin.Name && sb.Origin == s.Target.Name && sb.Position == GetOppositePosition( s.Position )); }
public bool Contains( SimpleBinding binding ) { return Bindings.Any( sb => Comparer( sb, binding ) ); }
public void Unbind( IWindowElement me, IWindowElement other, bool saveBinding = true ) { if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." ); if( me == null ) throw new ArgumentNullException( "me" ); if( other == null ) throw new ArgumentNullException( "other" ); SpatialBinding spatialBinding = null; if( _spatialBindings.TryGetValue( me, out spatialBinding ) ) { var binding = new SimpleBinding { Target = me, Origin = other }; var evt = new WindowBindingEventArgs { Binding = binding, BindingType = BindingEventType.Detach }; if( BeforeBinding != null ) BeforeBinding( this, evt ); if( evt.Canceled == false ) { Debug.Assert( me == spatialBinding.Window ); if( spatialBinding.Bottom != null && spatialBinding.Bottom.Window == other ) { //UnbindButtonManager.Service.RemoveButton( spatialBinding.Bottom.UnbindButton ); spatialBinding.Bottom = null; Unbind( other, me, saveBinding ); } if( spatialBinding.Left != null && spatialBinding.Left.Window == other ) { //UnbindButtonManager.Service.RemoveButton( spatialBinding.Left.UnbindButton ); spatialBinding.Left = null; Unbind( other, me, saveBinding ); } if( spatialBinding.Top != null && spatialBinding.Top.Window == other ) { //UnbindButtonManager.Service.RemoveButton( spatialBinding.Top.UnbindButton ); spatialBinding.Top = null; Unbind( other, me, saveBinding ); } if( spatialBinding.Right != null && spatialBinding.Right.Window == other ) { //UnbindButtonManager.Service.RemoveButton( spatialBinding.Right.UnbindButton ); spatialBinding.Right = null; Unbind( other, me, saveBinding ); } if( spatialBinding.IsAlone ) _spatialBindings.Remove( me ); if( !saveBinding ) _persistantBindings.Remove( binding ); } var evtAfter = new WindowBindedEventArgs { Binding = binding, BindingType = BindingEventType.Detach }; if( AfterBinding != null ) AfterBinding( this, evtAfter ); } }
public IBindResult PreviewUnbind( IWindowElement target, IWindowElement origin ) { if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." ); var binding = new SimpleBinding { Target = target, Origin = origin }; var evt = new WindowBindedEventArgs { Binding = binding, BindingType = BindingEventType.Detach }; if( PreviewBinding != null ) PreviewBinding( this, evt ); return new UnbindResult( this, binding ); }
public IBindResult PreviewBind( IWindowElement target, IWindowElement origin, BindingPosition position ) { if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." ); if( target == null ) throw new ArgumentNullException( "master" ); if( origin == null ) throw new ArgumentNullException( "slave" ); SpatialBinding targetSpatialBinding = null; SpatialBinding originSpatialBinding = null; if( CanBind( target, origin, position, out targetSpatialBinding, out originSpatialBinding ) ) { var binding = new SimpleBinding { Target = target, Origin = origin, Position = position }; var evt = new WindowBindedEventArgs { Binding = binding, BindingType = BindingEventType.Attach }; if( PreviewBinding != null ) PreviewBinding( this, evt ); return new BindResult( this, binding ); } return NullResult.Default; }
public void Bind( IWindowElement master, IWindowElement slave, BindingPosition position, bool saveBinding = false ) { if( Dispatcher.CurrentDispatcher != Application.Current.Dispatcher ) throw new InvalidOperationException( "This method should only be called by the Application Thread." ); if( master == null ) throw new ArgumentNullException( "master" ); if( slave == null ) throw new ArgumentNullException( "slave" ); //Console.WriteLine( "BIND thread id: {0} TimeSpan : {1}", Thread.CurrentThread.ManagedThreadId, DateTime.Now.Ticks ); // Spatial binding point of view using( _logger.OpenGroup( LogLevel.Info, "Attaching {0} on {1} at {2}", master.Name, slave.Name, position.ToString() ) ) { SpatialBinding spatialBinding = null; SpatialBinding slaveSpatialBinding = null; if( CanBind( master, slave, position, out spatialBinding, out slaveSpatialBinding ) ) { _logger.Trace( "Before binding..." ); var binding = new SimpleBinding { Target = master, Origin = slave, Position = position }; var evt = new WindowBindingEventArgs { Binding = binding, BindingType = BindingEventType.Attach }; if( BeforeBinding != null ) BeforeBinding( this, evt ); if( evt.Canceled == true ) { _logger.Trace( "...canceled. The reason was {0}.", evt.CancelReason ?? "No Reason" ); } else { if( spatialBinding == null ) { spatialBinding = new SpatialBinding( master ); _spatialBindings.Add( master, spatialBinding ); } if( slaveSpatialBinding == null ) { slaveSpatialBinding = new SpatialBinding( slave ); _spatialBindings.Add( slave, slaveSpatialBinding ); } Debug.Assert( spatialBinding != null ); Debug.Assert( slaveSpatialBinding != null ); //TODO : FIXWITHDOCKING if( position == BindingPosition.Top ) { spatialBinding.Top = slaveSpatialBinding; slaveSpatialBinding.Bottom = spatialBinding; } if( position == BindingPosition.Left ) { spatialBinding.Left = slaveSpatialBinding; slaveSpatialBinding.Right = spatialBinding; } if( position == BindingPosition.Bottom ) { spatialBinding.Bottom = slaveSpatialBinding; slaveSpatialBinding.Top = spatialBinding; } if( position == BindingPosition.Right ) { spatialBinding.Right = slaveSpatialBinding; slaveSpatialBinding.Left = spatialBinding; } if( saveBinding ) _persistantBindings.Add( binding ); var evtAfter = new WindowBindedEventArgs { Binding = binding, BindingType = BindingEventType.Attach }; _logger.Trace( "After binding..." ); if( AfterBinding != null ) AfterBinding( this, evtAfter ); } } } }
private static void AssertParse(Expression<Func<TestModel, object>> expression, string expectedExpressionText) { var actualExpressionText = new SimpleBinding<TestModel> { ValueExpression = expression }.ExpressionAsText(); Assert.AreEqual(expectedExpressionText, actualExpressionText); }