internal void UpdateAdvanceOptionsForItem(DependencyObject dependencyObject, DependencyPropertyDescriptor dpDescriptor, out object tooltip) { tooltip = StringConstants.Default; bool isResource = false; bool isDynamicResource = false; //TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style(maybe with StaticResourceExtension) isResource = typeof(Style).IsAssignableFrom(this.PropertyType); isDynamicResource = typeof(DynamicResourceExtension).IsAssignableFrom(this.PropertyType); if (isResource || isDynamicResource) { tooltip = StringConstants.Resource; } else { if ((dependencyObject != null) && (dpDescriptor != null)) { if (BindingOperations.GetBindingExpressionBase(dependencyObject, dpDescriptor.DependencyProperty) != null) { tooltip = StringConstants.Databinding; } else { BaseValueSource bvs = DependencyPropertyHelper .GetValueSource(dependencyObject, dpDescriptor.DependencyProperty) .BaseValueSource; switch (bvs) { case BaseValueSource.Inherited: case BaseValueSource.DefaultStyle: case BaseValueSource.ImplicitStyleReference: tooltip = StringConstants.Inheritance; break; case BaseValueSource.DefaultStyleTrigger: break; case BaseValueSource.Style: tooltip = StringConstants.StyleSetter; break; case BaseValueSource.Local: tooltip = StringConstants.Local; break; } } } else { // When the Value is diferent from the DefaultValue, use the local icon. if (!object.Equals(this.Value, this.DefaultValue)) { if (this.DefaultValue != null) { tooltip = StringConstants.Local; } else { if (this.PropertyType.IsValueType) { var defaultValue = Activator.CreateInstance(this.PropertyType); // When the Value is diferent from the DefaultValue, use the local icon. if (!object.Equals(this.Value, defaultValue)) { tooltip = StringConstants.Local; } } else { // When the Value is diferent from null, use the local icon. if (this.Value != null) { tooltip = StringConstants.Local; } } } } } } }
public override object ProvideValue(IServiceProvider serviceProvider) { IProvideValueTarget service = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; if (service == null) { return(this); } targetProperty = service.TargetProperty as DependencyProperty; targetObject = service.TargetObject as DependencyObject; if (targetObject == null || targetProperty == null) { return(this); } try { if (string.IsNullOrEmpty(Key)) { if (targetObject != null && targetProperty != null) { string context = targetObject.GetContextByName(); string obj = targetObject.FormatForTextId(); string property = targetProperty.ToString(); Key = $"{context}.{obj}.{property}"; } else if (!string.IsNullOrEmpty(DefaultValue)) { Key = DefaultValue; } } } catch (InvalidCastException) { // For Xaml Design Time Key = Guid.NewGuid().ToString(); } if (IsDynamic) { Binding binding = new Binding("TranslatedText") { Source = new Translation() { Key = Key, DefaultValue = DefaultValue, Language = Language } }; if (Converter != null) { binding.Converter = Converter; binding.ConverterParameter = ConverterParameter; //binding.ConverterCulture = ConverterCulture; } BindingOperations.SetBinding(targetObject, targetProperty, binding); return(binding.ProvideValue(serviceProvider)); } else { object result = Prefix + Translate.Get(Language, Key, DefaultValue) + Suffix; if (Converter != null) { result = Converter.Convert(result, targetProperty.PropertyType, ConverterParameter, ConverterCulture); } return(result); } }
/// <summary> /// Return the object associated with (collection, cvs, type). /// If this is the first reference to this view, add it to the tables. /// </summary> /// <exception cref="ArgumentException"> /// Thrown when the collectionViewType does not implement ICollectionView /// or does not have a constructor that accepts the type of collection. /// Also thrown when the named collection view already exists and is /// not the specified collectionViewType. /// </exception> internal ViewRecord GetViewRecord(object collection, CollectionViewSource cvs, Type collectionViewType, bool createView, Func <object, object> GetSourceItem) { // Order of precendence in acquiring the View: // 0) If collection is already a CollectionView, return it. // 1) If the CollectionView for this collection has been cached, then // return the cached instance. // 2) If a CollectionView derived type has been passed in collectionViewType // create an instance of that Type // 3) If the collection is an ICollectionViewFactory use ICVF.CreateView() // from the collection // 4) If the collection is an IListSource call GetList() and perform 5), // etc. on the returned list // 5) If the collection is an IBindingList return a new BindingListCollectionView // 6) If the collection is an IList return a new ListCollectionView // 7) If the collection is an IEnumerable, return a new CollectionView // (it uses the ListEnumerable wrapper) // 8) return null // An IListSource must share the view with its underlying list. // if the view already exists, just return it // Also, return null if it doesn't exist and we're called in "lazy" mode ViewRecord viewRecord = GetExistingView(collection, cvs, collectionViewType, GetSourceItem); if (viewRecord != null || !createView) { return(viewRecord); } // If the collection is an IListSource, it uses the same view as its // underlying list. IListSource ils = collection as IListSource; IList ilsList = null; if (ils != null) { ilsList = ils.GetList(); viewRecord = GetExistingView(ilsList, cvs, collectionViewType, GetSourceItem); if (viewRecord != null) { return(CacheView(collection, cvs, (CollectionView)viewRecord.View, viewRecord)); } } // Create a new view ICollectionView icv = collection as ICollectionView; if (icv != null) { icv = new CollectionViewProxy(icv); } else if (collectionViewType == null) { // Caller didn't specify a type for the view. ICollectionViewFactory icvf = collection as ICollectionViewFactory; if (icvf != null) { // collection is a view factory - call its factory method icv = icvf.CreateView(); } else { // collection is not a factory - create an appropriate view IList il = (ilsList != null) ? ilsList : collection as IList; if (il != null) { // create a view on an IList or IBindingList IBindingList ibl = il as IBindingList; if (ibl != null) { icv = new BindingListCollectionView(ibl); } else { icv = new ListCollectionView(il); } } else { // collection is not IList, wrap it IEnumerable ie = collection as IEnumerable; if (ie != null) { icv = new EnumerableCollectionView(ie); } } } } else { // caller specified a type for the view. Try to honor it. if (!typeof(ICollectionView).IsAssignableFrom(collectionViewType)) { throw new ArgumentException(SR.Get(SRID.CollectionView_WrongType, collectionViewType.Name)); } // if collection is IListSource, get its list first ( object arg = (ilsList != null) ? ilsList : collection; try { icv = Activator.CreateInstance(collectionViewType, System.Reflection.BindingFlags.CreateInstance, null, new object[1] { arg }, null) as ICollectionView; } catch (MissingMethodException e) { throw new ArgumentException(SR.Get(SRID.CollectionView_ViewTypeInsufficient, collectionViewType.Name, collection.GetType()), e); } } // if we got a view, add it to the tables if (icv != null) { // if the view doesn't derive from CollectionView, create a proxy that does CollectionView cv = icv as CollectionView; if (cv == null) { cv = new CollectionViewProxy(icv); } if (ilsList != null) // IListSource's list shares the same view { viewRecord = CacheView(ilsList, cvs, cv, null); } viewRecord = CacheView(collection, cvs, cv, viewRecord); // raise the event for a new view BindingOperations.OnCollectionViewRegistering(cv); } return(viewRecord); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); var item = GetTemplateChild("PART_Title") as FrameworkElement; if (item != null) { item.MouseMove += Rectangle_Title_MouseMove; item.MouseDown += Rectangle_MouseDown; item.MouseUp += Rectangle_MouseUp; } var rhiType = GetTemplateChild("PART_RhiType") as TextBlock; if (rhiType != null) { BindingOperations.SetBinding(rhiType, TextBlock.TextProperty, new Binding("RHIType") { Source = EngineNS.CEngine.Instance.Desc }); } var tgBtn = GetTemplateChild("PART_Button_TopMost") as System.Windows.Controls.Primitives.ToggleButton; if (tgBtn != null) { tgBtn.IsChecked = this.Topmost; tgBtn.SetBinding(System.Windows.Controls.Primitives.ToggleButton.IsCheckedProperty, new Binding("Topmost") { Source = this, Mode = BindingMode.TwoWay }); } var btn = GetTemplateChild("PART_Button_FillHorizontal") as Button; if (btn != null) { btn.Click += Button_FillHorizontal_Click; } btn = GetTemplateChild("PART_Button_FillVertical") as Button; if (btn != null) { btn.Click += Button_FillVertical_Click; } btn = GetTemplateChild("PART_Button_Minimized") as Button; if (btn != null) { btn.Click += Button_Minimized_Click; } btn = GetTemplateChild("PART_Button_Maximized") as Button; if (btn != null) { btn.Click += Button_Maximized_Click; } btn = GetTemplateChild("PART_Button_Restore") as Button; if (btn != null) { btn.Click += Button_Maximized_Click; } btn = GetTemplateChild("PART_Button_Close") as Button; if (btn != null) { btn.Click += Button_Close_Click; } mPART_Rect_Top = GetTemplateChild("PART_Rect_Top") as Rectangle; mPART_Rect_Bottom = GetTemplateChild("PART_Rect_Bottom") as Rectangle; mPART_Rect_Left = GetTemplateChild("PART_Rect_Left") as Rectangle; mPART_Rect_Right = GetTemplateChild("PART_Rect_Right") as Rectangle; mPART_Rect_TopLeft = GetTemplateChild("PART_Rect_TopLeft") as Rectangle; mPART_Rect_BottomLeft = GetTemplateChild("PART_Rect_BottomLeft") as Rectangle; mPART_Rect_TopRight = GetTemplateChild("PART_Rect_TopRight") as Rectangle; mPART_Rect_BottomRight = GetTemplateChild("PART_Rect_BottomRight") as Rectangle; mCustomBorderThickness = this.BorderThickness; }
public BindingExpressionBase SetBinding(DependencyProperty property, BindingBase binding) { return(BindingOperations.SetBinding(this, property, binding)); }
private UIElement GetInputControl(PropertyInfo item, object source) { Binding binding = new Binding() { Source = source, // view model? Path = new PropertyPath(item.Name), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; var enumDataTypeAtt = item.GetCustomAttribute <EnumDataTypeAttribute>(true); if (enumDataTypeAtt != null) { ComboBox ddrop = new ComboBox() { AllowDrop = true, Width = 150, HorizontalAlignment = HorizontalAlignment.Left }; foreach (var v in Enum.GetValues(enumDataTypeAtt.EnumType)) { ddrop.Items.Add(v.ToString()); } BindingOperations.SetBinding(ddrop, ComboBox.SelectedValueProperty, binding); return(ddrop); } if (item.PropertyType == typeof(string)) { var textbox = new TextBox() { MaxWidth = 400 }; BindingOperations.SetBinding(textbox, TextBox.TextProperty, binding); return(textbox); } if (item.PropertyType == typeof(bool)) { var checkbox = new CheckBox(); BindingOperations.SetBinding(checkbox, CheckBox.IsCheckedProperty, binding); return(checkbox); } if (item.PropertyType == typeof(int) || item.PropertyType == typeof(double)) { var range = item.GetCustomAttributes <RangeAttribute>(true).FirstOrDefault(); if (range != null) { NumericUpDown numberic = new NumericUpDown() { Minimum = Convert.ToDouble(range.Minimum), Maximum = Convert.ToDouble(range.Maximum), InterceptArrowKeys = true, Interval = 10, Width = 150, HorizontalAlignment = HorizontalAlignment.Left, }; BindingOperations.SetBinding(numberic, NumericUpDown.ValueProperty, binding); return(numberic); } var numberTextbox = new TextBox() { Width = 150, HorizontalAlignment = HorizontalAlignment.Left }; BindingOperations.SetBinding(numberTextbox, TextBox.TextProperty, binding); return(numberTextbox); } return(new TextBox()); }
public void Dispose() { BindingOperations.ClearBinding(this, ValueProperty); }
private void UnBindProject() { ProjectView.UnbindFromProject(); BindingOperations.ClearBinding(this, TitleProperty); }
private void ButtonOK_Click(object sender, RoutedEventArgs e) { if (Games == null) { if (string.IsNullOrWhiteSpace(TextName.Text)) { PlayniteMessageBox.Show("Name cannot be empty.", "Invalid game data", MessageBoxButton.OK, MessageBoxImage.Error); return; } } if (!string.IsNullOrEmpty(TextReleaseDate.Text) && !DateTime.TryParseExact(TextReleaseDate.Text, Playnite.Constants.DateUiFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date)) { PlayniteMessageBox.Show("Release date in is not valid format.", "Invalid game data", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (IsNameBindingDirty && CheckName.IsChecked == true) { BindingOperations.GetBindingExpression(TextName, TextBox.TextProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.Name = Game.Name; } } } if (IsGenreBindingDirty && CheckGenres.IsChecked == true) { BindingOperations.GetBindingExpression(TextGenres, TextBox.TextProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.Genres = Game.Genres; } } } if (IsReleaseDateBindingDirty && CheckReleaseDate.IsChecked == true) { BindingOperations.GetBindingExpression(TextReleaseDate, TextBox.TextProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.ReleaseDate = Game.ReleaseDate; } } } if (IsDeveloperBindingDirty && CheckDeveloper.IsChecked == true) { BindingOperations.GetBindingExpression(TextDeveloper, TextBox.TextProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.Developers = Game.Developers; } } } if (IsPublisherBindingDirty && CheckPublisher.IsChecked == true) { BindingOperations.GetBindingExpression(TextPublisher, TextBox.TextProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.Publishers = Game.Publishers; } } } if (IsCategoriesBindingDirty && CheckCategories.IsChecked == true) { BindingOperations.GetBindingExpression(TextCategories, TextBox.TextProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.Categories = Game.Categories; } } } if (IsDescriptionBindingDirty && CheckDescription.IsChecked == true) { BindingOperations.GetBindingExpression(TextDescription, TextBox.TextProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.Description = Game.Description; } } } if (IsInstallDirBindingDirty) { BindingOperations.GetBindingExpression(TextInstallDir, TextBox.TextProperty).UpdateSource(); } if (IsIsoPathBindingDirty) { BindingOperations.GetBindingExpression(TextIso, TextBox.TextProperty).UpdateSource(); } if (IsPlatformBindingDirty && CheckPlatform.IsChecked == true) { BindingOperations.GetBindingExpression(ComboPlatforms, ComboBox.SelectedValueProperty).UpdateSource(); if (Games != null) { foreach (var game in Games) { game.PlatformId = Game.PlatformId; } } } if (IsIconBindingDirty && CheckIcon.IsChecked == true) { var iconPath = ((BitmapImage)ImageIcon.Source).UriSource.OriginalString; var fileName = Guid.NewGuid().ToString() + Path.GetExtension(iconPath); var iconId = "images/custom/" + fileName; GameDatabase.Instance.AddImage(iconId, fileName, File.ReadAllBytes(iconPath)); if (Games != null) { foreach (var game in Games) { if (!string.IsNullOrEmpty(game.Icon)) { GameDatabase.Instance.DeleteImageSafe(game.Icon, game); } game.Icon = iconId; } } else { if (!string.IsNullOrEmpty(Game.Icon)) { GameDatabase.Instance.DeleteImageSafe(Game.Icon, Game); } Game.Icon = iconId; } if (Path.GetDirectoryName(iconPath) == Paths.TempPath) { File.Delete(iconPath); } } if (IsImageBindingDirty && CheckImage.IsChecked == true) { var imagePath = ((BitmapImage)ImageImage.Source).UriSource.OriginalString; var fileName = Guid.NewGuid().ToString() + Path.GetExtension(imagePath); var imageId = "images/custom/" + fileName; GameDatabase.Instance.AddImage(imageId, fileName, File.ReadAllBytes(imagePath)); if (Games != null) { foreach (var game in Games) { if (!string.IsNullOrEmpty(game.Image)) { GameDatabase.Instance.DeleteImageSafe(game.Image, game); } game.Image = imageId; } } else { if (!string.IsNullOrEmpty(Game.Image)) { GameDatabase.Instance.DeleteImageSafe(Game.Image, Game); } Game.Image = imageId; } if (Path.GetDirectoryName(imagePath) == Paths.TempPath) { File.Delete(imagePath); } } if (Games == null) { if (!Game.PlayTask.IsEqualJson(TempPlayTask)) { Game.PlayTask = TempPlayTask; } if (!Game.OtherTasks.IsEqualJson(TempOtherTasks)) { Game.OtherTasks = TempOtherTasks; } if (!Game.Links.IsEqualJson(TempLinks) && CheckLinks.IsChecked == true) { Game.Links = TempLinks; } } if (Games != null) { foreach (var game in Games) { GameDatabase.Instance.UpdateGameInDatabase(game); } } else { GameDatabase.Instance.UpdateGameInDatabase(Game); } DialogResult = true; Close(); }
public override void OnSeriesUpdateStart() { ActiveSplitters = 0; if (SplittersCollector == int.MaxValue - 1) { //just in case! Splitters.ForEach(s => s.SplitterCollectorIndex = 0); SplittersCollector = 0; } SplittersCollector++; if (Figure != null) { var xIni = ChartFunctions.ToDrawMargin(Values.Limit1.Min, AxisOrientation.X, Model.Chart, ScalesXAt); if (Model.Chart.View.DisableAnimations) { Figure.StartPoint = new Point(xIni, Model.Chart.DrawMargin.Height); } else { Figure.BeginAnimation(PathFigure.StartPointProperty, new PointAnimation(new Point(xIni, Model.Chart.DrawMargin.Height), Model.Chart.View.AnimationsSpeed)); } } if (IsPathInitialized) { return; } IsPathInitialized = true; Path = new Path(); BindingOperations.SetBinding(Path, Shape.StrokeProperty, new Binding { Path = new PropertyPath(StrokeProperty), Source = this }); BindingOperations.SetBinding(Path, Shape.FillProperty, new Binding { Path = new PropertyPath(FillProperty), Source = this }); BindingOperations.SetBinding(Path, Shape.StrokeThicknessProperty, new Binding { Path = new PropertyPath(StrokeThicknessProperty), Source = this }); BindingOperations.SetBinding(Path, VisibilityProperty, new Binding { Path = new PropertyPath(VisibilityProperty), Source = this }); BindingOperations.SetBinding(Path, Shape.StrokeDashArrayProperty, new Binding { Path = new PropertyPath(StrokeDashArrayProperty), Source = this }); var geometry = new PathGeometry(); Figure = new PathFigure(); geometry.Figures.Add(Figure); Path.Data = geometry; Model.Chart.View.AddToDrawMargin(Path); var x = ChartFunctions.ToDrawMargin(ActualValues.Limit1.Min, AxisOrientation.X, Model.Chart, ScalesXAt); Figure.StartPoint = new Point(x, Model.Chart.DrawMargin.Height); var i = Model.Chart.View.Series.IndexOf(this); Panel.SetZIndex(Path, Model.Chart.View.Series.Count - i); }
private void PrintLines() { foreach (ACLineSegment l in Singleton.Instance().AClines) { System.Windows.Shapes.Line line = new System.Windows.Shapes.Line(); SolidColorBrush brush = new SolidColorBrush(); brush.Color = Colors.Green; line.StrokeThickness = 1; line.Stroke = brush; ConnectivityNode od = null; //cvor pocetni ConnectivityNode na = null; //dest foreach (Terminal terminal in l.terminali) { if (od == null) { foreach (CIM.IEC61970.Base.Core.Substation s in Singleton.Instance().Substations) { foreach (ConnectivityNode cvor in s.connectivityNodes) { if (cvor.mRID.Equals(terminal.ConnectivityNode.mRID)) { od = cvor; od.X = cvor.x + s.x + (s.connectivityNodes.IndexOf(cvor) * 50) + 10; od.Y = cvor.y + s.y + (s.connectivityNodes.IndexOf(cvor) * 50) + 10; break; } } } } else { foreach (CIM.IEC61970.Base.Core.Substation s in Singleton.Instance().Substations) { foreach (ConnectivityNode cvor1 in s.connectivityNodes) { if (cvor1.mRID.Equals(terminal.ConnectivityNode.mRID)) { na = cvor1; na.X = cvor1.x + s.x + (s.connectivityNodes.IndexOf(cvor1) * 50) + 10; na.Y = cvor1.y + s.y + (s.connectivityNodes.IndexOf(cvor1) * 50) + 10; break; } } } } } BindingOperations.SetBinding(line, System.Windows.Shapes.Line.X1Property, new Binding { Source = od, Path = new PropertyPath("X") }); BindingOperations.SetBinding(line, System.Windows.Shapes.Line.Y1Property, new Binding { Source = od, Path = new PropertyPath("Y") }); BindingOperations.SetBinding(line, System.Windows.Shapes.Line.X2Property, new Binding { Source = na, Path = new PropertyPath("X") }); BindingOperations.SetBinding(line, System.Windows.Shapes.Line.Y2Property, new Binding { Source = na, Path = new PropertyPath("Y") }); viewCanvas.Children.Add(line); } }
/// <summary> /// Handles the loading of this control into the visual tree. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The unused routed event arguments.</param> private void OnLoaded(object sender, RoutedEventArgs e) { this.tabControl = new TabControl(); ViewerEquityBlotter.staticTabControl = this.tabControl; this.SetValue(Page.ContentProperty, tabControl); // Working Order Tab this.tabWorkingOrder = new TabItem(); this.tabWorkingOrder.Header = "Working Orders"; // Match Tab this.tabMatch = new TabItem(); ViewerEquityBlotter.staticMatchTab = this.tabMatch; this.tabMatch.Header = "Matches"; this.matchGrid = new Grid(); this.matchRow0 = new RowDefinition(); this.matchRow0.Height = new GridLength(1.0, GridUnitType.Star); this.matchGrid.RowDefinitions.Add(matchRow0); this.matchRow1 = new RowDefinition(); this.matchRow1.Height = GridLength.Auto; this.matchGrid.RowDefinitions.Add(matchRow1); this.row1Grid = new Grid(); Grid.SetColumn(this.row1Grid, 0); Grid.SetRow(this.row1Grid, 0); ColumnDefinition matchColumn10 = new ColumnDefinition(); matchColumn10.Width = new GridLength(1.0, GridUnitType.Star); this.row1Grid.ColumnDefinitions.Add(matchColumn10); ColumnDefinition matchColumn11 = new ColumnDefinition(); matchColumn11.Width = GridLength.Auto; this.row1Grid.ColumnDefinitions.Add(matchColumn11); this.matchGrid.Children.Add(this.row1Grid); this.tabExecution = new TabItem(); this.tabExecution.Header = "Execution"; //this.executionGrid = new Grid(); //this.executionGrid.Children.Add(ViewerEquityBlotter.reportExecution); // Create the settlement report horizontal splitter. //this.tabExecution.Content = executionGrid; this.tabExecution.Content = ViewerEquityBlotter.reportExecution; // Add the tabs to the page. tabControl.Items.Add(this.tabWorkingOrder); tabControl.Items.Add(this.tabMatch); tabControl.Items.Add(this.tabExecution); // The lion's share of time to load a report is adding the child user interface elements to the report. Recycling the cells from one report to // another makes things move much faster. The viewer creates a single, static Prototype Report for its content and reuses it from one viewer to // the next. The downside to this architecture is that the binding must be done in code because the XAML doesn't have access to the static report. this.tabWorkingOrder.Content = ViewerEquityBlotter.reportWorkingOrder; this.row1Grid.Children.Add(ViewerEquityBlotter.reportMatch); this.row1Grid.Children.Add(ViewerEquityBlotter.negotiationConsole); Grid.SetColumn(ViewerEquityBlotter.reportMatch, 0); Grid.SetRow(ViewerEquityBlotter.reportMatch, 0); Grid.SetColumn(ViewerEquityBlotter.negotiationConsole, 1); Grid.SetRow(ViewerEquityBlotter.negotiationConsole, 0); this.tabMatch.Content = this.matchGrid; // This selects which orders are displayed in the viewer. ViewerEquityBlotter.reportWorkingOrder.BlotterId = this.blotter.BlotterId; ViewerEquityBlotter.reportMatch.BlotterId = this.blotter.BlotterId; ViewerEquityBlotter.reportExecution.BlotterId = this.blotter.BlotterId; if (this.arguments.Length > 0) { if (this.arguments[0] is Match) { this.tabControl.SelectedItem = this.tabMatch; } } // Bind the "AnimationSpeed" property to the setting. Binding bindingAnimationSpeed = new Binding("AnimationSpeed"); bindingAnimationSpeed.Source = FluidTrade.Guardian.Properties.Settings.Default; bindingAnimationSpeed.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(this, ViewerEquityBlotter.AnimationSpeedProperty, bindingAnimationSpeed); // Bind the "IsFilledFilter" property to the setting. Binding bindingApplyFilledFilter = new Binding("IsFilledFilter"); bindingApplyFilledFilter.Source = FluidTrade.Guardian.Properties.Settings.Default; bindingApplyFilledFilter.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(this, ViewerEquityBlotter.IsFilledFilterProperty, bindingApplyFilledFilter); // Bind the "IsHeaderFrozen" property to the setting. Binding bindingApplyHeaderFrozen = new Binding("IsHeaderFrozen"); bindingApplyHeaderFrozen.Source = FluidTrade.Guardian.Properties.Settings.Default; bindingApplyHeaderFrozen.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(this, ViewerEquityBlotter.IsHeaderFrozenProperty, bindingApplyHeaderFrozen); // Bind the "IsLayoutFrozen" property to the setting. Binding bindingApplyLayoutFrozen = new Binding("IsLayoutFrozen"); bindingApplyLayoutFrozen.Source = FluidTrade.Guardian.Properties.Settings.Default; bindingApplyLayoutFrozen.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(this, ViewerEquityBlotter.IsLayoutFrozenProperty, bindingApplyLayoutFrozen); // Bind the "IsNavigationPaneVisible" property to the settings. Binding bindingIsNavigationPaneVisible = new Binding("IsNavigationPaneVisible"); bindingIsNavigationPaneVisible.Source = FluidTrade.Guardian.Properties.Settings.Default; bindingIsNavigationPaneVisible.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(this, ViewerEquityBlotter.IsNavigationPaneVisibleProperty, bindingIsNavigationPaneVisible); // Bind the "IsRunningFilter" property to the setting. Binding bindingApplyRunningFilter = new Binding("IsRunningFilter"); bindingApplyRunningFilter.Source = FluidTrade.Guardian.Properties.Settings.Default; bindingApplyRunningFilter.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(this, ViewerEquityBlotter.IsRunningFilterProperty, bindingApplyRunningFilter); // Bind the "Scale" property to the setting. Binding bindingSliderScale = new Binding("Scale"); bindingSliderScale.Source = FluidTrade.Guardian.Properties.Settings.Default; bindingSliderScale.Mode = BindingMode.TwoWay; BindingOperations.SetBinding(this, ViewerEquityBlotter.ScaleProperty, bindingSliderScale); }
/// <summary> /// Draws a path /// </summary> /// <param name="ops"></param> /// <param name="pen"></param> /// <param name="brush"></param> public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, NGraphics.Brush brush = null) { if (pen == null && brush == null) { return; } var pathEl = new Windows.UI.Xaml.Shapes.Path(); if (brush != null) { pathEl.Fill = GetBrush(brush); } if (pen != null) { pathEl.Stroke = GetStroke(pen); pathEl.StrokeThickness = pen.Width; } var geo = new StringBuilder(); foreach (var op in ops) { var mt = op as MoveTo; if (mt != null) { geo.AppendFormat(CultureInfo.InvariantCulture, " M {0},{1}", mt.Point.X, mt.Point.Y); continue; } var lt = op as LineTo; if (lt != null) { geo.AppendFormat(CultureInfo.InvariantCulture, " L {0},{1}", lt.Point.X, lt.Point.Y); continue; } var at = op as ArcTo; if (at != null) { var p = at.Point; var r = at.Radius; geo.AppendFormat(CultureInfo.InvariantCulture, " A {0},{1} 0 {2} {3} {4},{5}", r.Width, r.Height, at.LargeArc ? 1 : 0, at.SweepClockwise ? 1 : 0, p.X, p.Y); continue; } var ct = op as CurveTo; if (ct != null) { var p = ct.Point; var c1 = ct.Control1; var c2 = ct.Control2; geo.AppendFormat(CultureInfo.InvariantCulture, " C {0},{1} {2},{3} {4},{5}", c1.X, c1.Y, c2.X, c2.Y, p.X, p.Y); continue; } var cp = op as ClosePath; if (cp != null) { geo.Append(" z"); continue; } } // Convert path string to geometry var b = new Binding { Source = geo.ToString() }; BindingOperations.SetBinding(pathEl, Windows.UI.Xaml.Shapes.Path.DataProperty, b); pathEl.RenderTransform = Conversions.GetTransform(CurrentTransform); _canvas.Children.Add(pathEl); }
public static void UnLoadMonitor(Control control, DependencyProperty controlProperty = null) { var p = controlProperty ?? GetProperty(control); BindingOperations.ClearBinding(control, p); }
public AccountDetailsListViewModel() { accountDetailsList = new ObservableCollection <AccountDetailsViewModel>(); addAction = new Action <AccountDetailsViewModel>(Add); BindingOperations.EnableCollectionSynchronization(accountDetailsList, _collectionLock); }
public ObservableCollectionAsync(List <T> list) : base(list) { BindingOperations.EnableCollectionSynchronization(this, _lockObject); }
protected override Binding GetValidationBinding() { return(BindingOperations.GetBinding(TextBox, TextBox.TextProperty)); }
public ObservableCollectionAsync(IEnumerable <T> collection) : base(collection) { BindingOperations.EnableCollectionSynchronization(this, _lockObject); }
public ResultsViewModel() { Results = new ResultCollection(); BindingOperations.EnableCollectionSynchronization(Results, _collectionLock); }
private void CopyItemsSource(FrameworkElement element) { BindingOperations.SetBinding(element, ComboBox.ItemsSourceProperty, BindingOperations.GetBinding(this, ComboBox.ItemsSourceProperty)); }
private void SetupBindings() { var binding = new Binding() { Source = this, Path = new PropertyPath("ShowViewCube") }; BindingOperations.SetBinding(viewCube, ViewBoxModel3D.IsRenderingProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("ViewCubeHorizontalPosition") }; BindingOperations.SetBinding(viewCube, ViewBoxModel3D.RelativeScreenLocationXProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("ViewCubeVerticalPosition") }; BindingOperations.SetBinding(viewCube, ViewBoxModel3D.RelativeScreenLocationYProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("ViewCubeTexture") }; BindingOperations.SetBinding(viewCube, ViewBoxModel3D.ViewBoxTextureProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("ViewCubeSize") }; BindingOperations.SetBinding(viewCube, ViewBoxModel3D.SizeScaleProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("IsViewCubeEdgeClicksEnabled") }; BindingOperations.SetBinding(viewCube, ViewBoxModel3D.EnableEdgeClickProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("ModelUpDirection") }; BindingOperations.SetBinding(viewCube, ViewBoxModel3D.UpDirectionProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("ShowCoordinateSystem") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.IsRenderingProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemHorizontalPosition") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.RelativeScreenLocationXProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemVerticalPosition") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.RelativeScreenLocationYProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemLabelForeground") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.LabelColorProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemLabelX") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.CoordinateSystemLabelXProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemLabelY") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.CoordinateSystemLabelYProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemLabelZ") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.CoordinateSystemLabelZProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemAxisXColor") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.AxisXColorProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemAxisYColor") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.AxisYColorProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemAxisZColor") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.AxisZColorProperty, binding); binding = new Binding() { Source = this, Path = new PropertyPath("CoordinateSystemSize") }; BindingOperations.SetBinding(coordinateSystem, CoordinateSystemModel3D.SizeScaleProperty, binding); }
void SetBindings() { //set Binding for Name TextBox Binding b = new Binding(); b.Mode = BindingMode.TwoWay; b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; b.Source = p; b.Path = new PropertyPath("Name"); BindingOperations.SetBinding(this.tbPersonName, TextBox.TextProperty, b); //set Binding for Job TextBox Binding b1 = new Binding(); b1.Mode = BindingMode.OneWayToSource; b1.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus; b1.Source = p; b1.Path = new PropertyPath("Job"); BindingOperations.SetBinding(this.tbPersonJob, TextBox.TextProperty, b1); //set Binding for Age TextBox Binding b2 = new Binding(); b2.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus; b2.Source = p; b2.Mode = BindingMode.TwoWay; b2.ValidationRules.Add(new AgeValidationRule()); b2.Path = new PropertyPath("Age"); BindingOperations.SetBinding(this.tbPersonAge, TextBox.TextProperty, b2); //set Binding for Salary TextBox Binding b3 = new Binding(); b3.Source = p; b3.Mode = BindingMode.TwoWay; b3.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; b3.Path = new PropertyPath("Salary"); BindingOperations.SetBinding(this.tbPersonSalary, TextBox.TextProperty, b3); //Set Binding for Interest TextBox Binding b4 = new Binding(); b4.Source = p; b4.Mode = BindingMode.OneWay; b4.Path = new PropertyPath("Interest"); BindingOperations.SetBinding(this.tbPersonInterest, TextBox.TextProperty, b4); //set Binding for Name Label Binding b5 = new Binding(); b5.Source = p; b5.Path = new PropertyPath("Name"); BindingOperations.SetBinding(this.lblPersonName, Label.ContentProperty, b5); //set Binding for Job Label Binding b6 = new Binding(); b6.Source = p; b6.Path = new PropertyPath("Job"); BindingOperations.SetBinding(this.lblPersonJob, Label.ContentProperty, b6); //set Binding for Age Label; Binding b7 = new Binding(); b7.Source = p; b7.Path = new PropertyPath("Age"); BindingOperations.SetBinding(this.lblPersonAge, Label.ContentProperty, b7); //set Binding for Salary Label Binding b8 = new Binding(); b8.Source = p; b8.Converter = new SalaryFormmatingConverter(); b8.Path = new PropertyPath("Salary"); BindingOperations.SetBinding(this.lblPersonSalary, Label.ContentProperty, b8); //set Binding for Label Interest Binding b9 = new Binding(); b9.Source = p; b9.Path = new PropertyPath("Interest"); BindingOperations.SetBinding(this.lblPersonInterest, Label.ContentProperty, b9); //set Binding for ListBox lb.ItemsSource = pers; }
public CollectPreviewComputerEntry() { Items = new ObservableCollection <CollectPreviewFileEntry>(); BindingOperations.EnableCollectionSynchronization(Items, _itemsLock); }
private void BuildDynamicGrid(ContentControl grid) { if (grid == null) { return; } PropertyInfo itemsProperty = DataContext.GetInstanceProperties().FirstOrDefault(pi => pi.Name == "Items"); DataGrid gridControl = ItemsControlProvider.ProvideGridControl(itemsProperty, DataContext); if (SelectedItemBinding != null) { gridControl.SetBinding(Selector.SelectedItemProperty, SelectedItemBinding); } //set datagrid queryable sorting gridControl.Sorting += (o, e) => { var dc = DataContext as IPagedQueryable; if (dc == null) { return; } if (e.Column.SortDirection.HasValue == false || e.Column.SortDirection.Value == ListSortDirection.Descending) { dc.BeginInit(); dc.SortColumn = e.Column.SortMemberPath; dc.SortDirection = (SortDirection)ListSortDirection.Ascending; dc.EndInit(); e.Column.SortDirection = ListSortDirection.Ascending; } else { dc.BeginInit(); dc.SortColumn = e.Column.SortMemberPath; dc.SortDirection = (SortDirection)ListSortDirection.Descending; dc.EndInit(); e.Column.SortDirection = ListSortDirection.Descending; } e.Handled = true; }; gridControl.SelectionChanged += (o, e) => { var gc = o as DataGrid; if (gc == null) { return; } var dc = gc.DataContext as IPagedQueryable; if (dc == null) { return; } dc.ChangeSelection(e.RemovedItems, e.AddedItems); }; gridControl.MouseDown += (o, e) => { var gc = o as DataGrid; if (gc == null) { return; } var dc = gc.DataContext as IPagedQueryable; if (dc == null) { return; } if (e.ChangedButton == MouseButton.XButton1) { if (dc.CanMovePrevious) { dc.MovePrevious(); } } if (e.ChangedButton == MouseButton.XButton2) { if (dc.CanMoveNext) { dc.MoveNext(); } } }; gridControl.Unloaded += (o, e) => { var control = o as DataGrid; if (control == null) { return; } BindingOperations.ClearAllBindings(control); }; grid.SetValue(ContentControl.ContentProperty, gridControl); }
public void Dispose() { BindingOperations.ClearBinding(this, HasErrorProxyProperty); }
private void TextBox_LostFocus(object sender, RoutedEventArgs e) { TextBox text = sender as TextBox; BindingOperations.GetBindingExpression(text, TextBox.TextProperty).UpdateSource(); }
/// <summary> /// Called when the control template has been applied. /// </summary> public override void OnApplyTemplate() { PART_Popup = GetTemplateChild("PART_Popup") as PinnedPopup; PART_RapidFindReplaceControl = GetTemplateChild("PART_RapidFindReplaceControl") as RapidFindReplaceControl; PART_CloseButton = GetTemplateChild("PART_CloseButton") as Button; PART_Thumb = GetTemplateChild("PART_Thumb") as Thumb; PART_MoveThumb = GetTemplateChild("PART_MoveThumb") as Thumb; if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))//Blend uses a StandinPopup class so PART_OptionsPopup will be null { Window parentWindow = Utility.FindWindow(this); if (PART_Popup.DockingPosition != PinnedPopup.DockPosition.None) { PART_Popup.DockingPosition = DockingPosition;//we want our instance to take precedence } focusMonitor = FocusMonitor.GetCreateInstanceFor(parentWindow); //if the PlacementTarget isn't set, get the window containing us if (ReadLocalValue(PlacementTargetProperty) == DependencyProperty.UnsetValue && !DesignerProperties.GetIsInDesignMode(this)) { PART_Popup.PlacementTarget = parentWindow; } else { PART_Popup.PlacementTarget = PlacementTarget; } BindingOperations.SetBinding(this, RapidFindReplacePopupControl.DockingPositionProperty, new Binding { Source = PART_Popup, Path = new PropertyPath("DockingPosition"), Mode = BindingMode.TwoWay }); BindingOperations.SetBinding(this, RapidFindReplacePopupControl.PlacementTargetProperty, new Binding { Source = PART_Popup, Path = new PropertyPath("PlacementTarget"), Mode = BindingMode.TwoWay }); BindingOperations.SetBinding(this, RapidFindReplacePopupControl.IsOpenProperty, new Binding { Source = PART_Popup, Path = new PropertyPath("IsOpen"), Mode = BindingMode.TwoWay }); CommandBinding findCommandBinding = new CommandBinding(ApplicationCommands.Find, (object target, ExecutedRoutedEventArgs e) => { IsOpen = true; }, (object target, CanExecuteRoutedEventArgs e) => { e.CanExecute = true; e.Handled = true; }); Window rootWindow = Utility.FindWindow(this); rootWindow.CommandBindings.Add(findCommandBinding); } #region Mirror properties from find box /* * //BodyHighlightAdornerBrush * if (BodyHighlightAdornerBrush!=null && BodyHighlightAdornerBrush != DependencyProperty.UnsetValue) * PART_RapidFindReplaceControl.BodyHighlightAdornerBrush = BodyHighlightAdornerBrush; * else * BodyHighlightAdornerBrush = PART_RapidFindReplaceControl.BodyHighlightAdornerBrush; * * BindingOperations.SetBinding(this, RapidFindReplacePopupControl.BodyHighlightAdornerBrushProperty, new Binding { Source = PART_RapidFindReplaceControl, Path = new PropertyPath("BodyHighlightAdornerBrush"), Mode = BindingMode.TwoWay, UpdateSourceTrigger=UpdateSourceTrigger.PropertyChanged }); * * * //BodyIterativeHighlightAdornerBrush * if (BodyIterativeHighlightAdornerBrush != null && BodyIterativeHighlightAdornerBrush != DependencyProperty.UnsetValue) * PART_RapidFindReplaceControl.BodyIterativeHighlightAdornerBrush = BodyIterativeHighlightAdornerBrush; * else * BodyIterativeHighlightAdornerBrush = PART_RapidFindReplaceControl.BodyIterativeHighlightAdornerBrush; * * BindingOperations.SetBinding(this, RapidFindReplacePopupControl.BodyIterativeHighlightAdornerBrushProperty, new Binding { Source = PART_RapidFindReplaceControl, Path = new PropertyPath("BodyIterativeHighlightAdornerBrush"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); * * //BodyHighlightAdornerPen * if (BodyHighlightAdornerPen != null && BodyHighlightAdornerPen != DependencyProperty.UnsetValue) * PART_RapidFindReplaceControl.BodyHighlightAdornerPen = BodyHighlightAdornerPen; * else * BodyHighlightAdornerPen = PART_RapidFindReplaceControl.BodyHighlightAdornerPen; * * BindingOperations.SetBinding(this, RapidFindReplacePopupControl.BodyHighlightAdornerPenProperty, new Binding { Source = PART_RapidFindReplaceControl, Path = new PropertyPath("BodyHighlightAdornerPen"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); */ if (PART_RapidFindReplaceControl != null) { BindTwoWayToFindBox(RapidFindReplacePopupControl.BodyHighlightAdornerBrushProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.BodyHighlightAdornerBrushProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.BodyIterativeHighlightAdornerBrushProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.BodyIterativeHighlightAdornerBrushProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.BodyHighlightAdornerPenProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.BodyHighlightAdornerPenProperty); BindingOperations.SetBinding(this, RapidFindReplacePopupControl.CurrentMatchProperty, new Binding { Source = PART_RapidFindReplaceControl, Path = new PropertyPath("CurrentMatch"), Mode = BindingMode.OneWay }); BindingOperations.SetBinding(this, RapidFindReplacePopupControl.NumberOfHitsProperty, new Binding { Source = PART_RapidFindReplaceControl, Path = new PropertyPath("NumberOfHits"), Mode = BindingMode.OneWay }); BindingOperations.SetBinding(this, RapidFindReplacePopupControl.IsQueryValidProperty, new Binding { Source = PART_RapidFindReplaceControl, Path = new PropertyPath("IsQueryValid"), Mode = BindingMode.OneWay }); BindingOperations.SetBinding(this, RapidFindReplacePopupControl.QueryHistoryProperty, new Binding { Source = PART_RapidFindReplaceControl, Path = new PropertyPath("QueryHistory"), Mode = BindingMode.OneWay }); BindTwoWayToFindBox(RapidFindReplacePopupControl.FindScopeProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.FindScopeProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.QueryProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.QueryProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.QueryHistoryCapacityProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.QueryHistoryCapacityProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.AsYouTypeFindMinimumCharactersProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.AsYouTypeFindMinimumCharactersProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.WatermarkTextProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.WatermarkTextProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.FindButtonIconProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.FindButtonIconProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.OptionsButtonIconProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.OptionsButtonIconProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.OptionsButtonCheckedIconProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.OptionsButtonCheckedIconProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.IsReplaceOpenProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.IsReplaceOpenProperty); BindTwoWayToFindBox(RapidFindReplacePopupControl.IsOptionsDropDownOpenProperty, PART_RapidFindReplaceControl, RapidFindReplaceControl.IsOptionsDropDownOpenProperty); } #endregion base.OnApplyTemplate(); }
/// <summary> /// Coerce visibility /// </summary> /// <param name="dependencyObject">Dependency object</param> /// <param name="baseValue">Base value</param> /// <returns>Coerced value</returns> private static object CoerceVisibility( DependencyObject dependencyObject, object baseValue) { // Make sure object is a framework element var frameworkElement = dependencyObject as FrameworkElement; if (frameworkElement == null) { return(baseValue); } // Cast to type safe value var visibility = (Visibility)baseValue; // If Visibility value hasn’t change, do nothing. // This can happen if the Visibility property is set using data binding // and the binding source has changed but the new visibility value // hasn’t changed. if (visibility == frameworkElement.Visibility) { return(baseValue); } // If element is not hooked by our attached property, stop here if (!IsHookedElement(frameworkElement)) { return(baseValue); } // Update animation flag // If animation already started, don’t restart it (otherwise, infinite loop) if (UpdateAnimationStartedFlag(frameworkElement)) { return(baseValue); } // If we get here, it means we have to start fade in or fade out animation. // In any case return value of this method will be Visibility.Visible, // to allow the animation. var doubleAnimation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(AnimationDuration)) }; // When animation completes, set the visibility value to the requested // value (baseValue) doubleAnimation.Completed += (sender, eventArgs) => { if (visibility == Visibility.Visible) { // In case we change into Visibility.Visible, the correct value // is already set, so just update the animation started flag UpdateAnimationStartedFlag(frameworkElement); } else { // This will trigger value coercion again // but UpdateAnimationStartedFlag() function will reture true // this time, thus animation will not be triggered. if (BindingOperations.IsDataBound(frameworkElement, UIElement.VisibilityProperty)) { // Set visiblity using bounded value var bindingValue = BindingOperations.GetBinding(frameworkElement, UIElement.VisibilityProperty); BindingOperations.SetBinding(frameworkElement, UIElement.VisibilityProperty, bindingValue ?? throw new InvalidOperationException()); } else { // No binding, just assign the value frameworkElement.Visibility = visibility; } } }; if (visibility == Visibility.Collapsed || visibility == Visibility.Hidden) { // Fade out by animating opacity doubleAnimation.From = 1.0; doubleAnimation.To = 0.0; } else { // Fade in by animating opacity doubleAnimation.From = 0.0; doubleAnimation.To = 1.0; } // Start animation frameworkElement.BeginAnimation(UIElement.OpacityProperty, doubleAnimation); // Make sure the element remains visible during the animation // The original requested value will be set in the completed event of // the animation return(Visibility.Visible); }
public Login(KinectSensorChooser kinectSensorChooser) { InitializeComponent(); // Set window to center of screen WindowStartupLocation = WindowStartupLocation.CenterScreen; // Set kinect sensor chooser this.kinectSensorChooser = kinectSensorChooser; // Binding Kinect sensor to Kinect Region var kinectRegionandSensorBinding = new Binding("Kinect") { Source = kinectSensorChooser }; BindingOperations.SetBinding(kinectKinectRegion, KinectRegion.KinectSensorProperty, kinectRegionandSensorBinding); #region KinectRegion // Setup Kinect region press target and event handlers KinectRegion.SetIsPressTarget(btnCancelLogin, true); KinectRegion.SetIsPressTarget(btnLogin, true); KinectRegion.SetIsPressTarget(btnA, true); KinectRegion.SetIsPressTarget(btnB, true); KinectRegion.SetIsPressTarget(btnC, true); KinectRegion.SetIsPressTarget(btnD, true); KinectRegion.SetIsPressTarget(btnE, true); KinectRegion.SetIsPressTarget(btnF, true); KinectRegion.SetIsPressTarget(btnG, true); KinectRegion.SetIsPressTarget(btnH, true); KinectRegion.SetIsPressTarget(btnI, true); KinectRegion.SetIsPressTarget(btnJ, true); KinectRegion.SetIsPressTarget(btnK, true); KinectRegion.SetIsPressTarget(btnL, true); KinectRegion.SetIsPressTarget(btnM, true); KinectRegion.SetIsPressTarget(btnN, true); KinectRegion.SetIsPressTarget(btnO, true); KinectRegion.SetIsPressTarget(btnP, true); KinectRegion.SetIsPressTarget(btnQ, true); KinectRegion.SetIsPressTarget(btnR, true); KinectRegion.SetIsPressTarget(btnS, true); KinectRegion.SetIsPressTarget(btnT, true); KinectRegion.SetIsPressTarget(btnU, true); KinectRegion.SetIsPressTarget(btnV, true); KinectRegion.SetIsPressTarget(btnW, true); KinectRegion.SetIsPressTarget(btnX, true); KinectRegion.SetIsPressTarget(btnY, true); KinectRegion.SetIsPressTarget(btnZ, true); KinectRegion.SetIsPressTarget(btnBackspace, true); KinectRegion.SetIsPressTarget(textBoxUsername, true); KinectRegion.SetIsPressTarget(passwordBox, true); // btnCancelLogin KinectRegion.AddHandPointerEnterHandler(btnCancelLogin, HandPointerEnterEvent); KinectRegion.AddHandPointerLeaveHandler(btnCancelLogin, HandPointerLeaveEvent); KinectRegion.AddHandPointerPressHandler(btnCancelLogin, HandPointerPressEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnCancelLogin, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnCancelLogin, HandPointerCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnCancelLogin, HandPointerLostCaptureEvent); // btnLogin KinectRegion.AddHandPointerEnterHandler(btnLogin, HandPointerEnterEvent); KinectRegion.AddHandPointerLeaveHandler(btnLogin, HandPointerLeaveEvent); KinectRegion.AddHandPointerPressHandler(btnLogin, HandPointerPressEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnLogin, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnLogin, HandPointerCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnLogin, HandPointerLostCaptureEvent); // textBoxUsername KinectRegion.AddHandPointerEnterHandler(textBoxUsername, HandPointerEnterEvent); KinectRegion.AddHandPointerLeaveHandler(textBoxUsername, HandPointerLeaveEvent); KinectRegion.AddHandPointerPressHandler(textBoxUsername, HandPointerPressEvent); KinectRegion.AddHandPointerPressReleaseHandler(textBoxUsername, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerGotCaptureHandler(textBoxUsername, HandPointerCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(textBoxUsername, HandPointerLostCaptureEvent); // passwordBox KinectRegion.AddHandPointerEnterHandler(passwordBox, HandPointerEnterEvent); KinectRegion.AddHandPointerLeaveHandler(passwordBox, HandPointerLeaveEvent); KinectRegion.AddHandPointerPressHandler(passwordBox, HandPointerPressEvent); KinectRegion.AddHandPointerPressReleaseHandler(passwordBox, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerGotCaptureHandler(passwordBox, HandPointerCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(passwordBox, HandPointerLostCaptureEvent); // Keyboard: Register event handlers // 1 - AddHandPointerEnterHandler KinectRegion.AddHandPointerEnterHandler(btnA, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnB, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnC, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnD, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnE, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnF, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnG, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnH, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnI, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnJ, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnK, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnL, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnM, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnN, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnO, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnP, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnQ, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnR, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnS, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnT, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnU, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnV, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnW, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnX, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnY, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnZ, HandPointerEnterEvent); KinectRegion.AddHandPointerEnterHandler(btnBackspace, HandPointerEnterEvent); // 2 - HandPointerEnterHandler KinectRegion.AddHandPointerLeaveHandler(btnA, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnB, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnC, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnD, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnE, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnF, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnG, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnH, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnI, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnJ, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnK, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnL, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnM, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnN, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnO, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnP, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnQ, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnR, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnS, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnT, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnU, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnV, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnW, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnX, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnY, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnZ, HandPointerLeaveEvent); KinectRegion.AddHandPointerLeaveHandler(btnBackspace, HandPointerLeaveEvent); // 3 - AddHandPointerPressHandler KinectRegion.AddHandPointerPressHandler(btnA, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnB, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnC, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnD, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnE, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnF, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnG, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnH, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnI, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnJ, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnK, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnL, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnM, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnN, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnO, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnP, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnQ, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnR, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnS, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnT, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnU, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnV, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnW, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnX, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnY, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnZ, HandPointerPressEvent); KinectRegion.AddHandPointerPressHandler(btnBackspace, HandPointerPressEvent); // 4 - AddHandPointerPressReleaseHandler KinectRegion.AddHandPointerPressReleaseHandler(btnA, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnB, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnC, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnD, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnE, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnF, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnG, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnH, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnI, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnJ, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnK, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnL, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnM, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnN, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnO, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnP, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnQ, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnR, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnS, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnT, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnU, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnV, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnW, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnX, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnY, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnZ, HandPointerPressReleaseEvent); KinectRegion.AddHandPointerPressReleaseHandler(btnBackspace, HandPointerPressReleaseEvent); // 5 - AddHandPointerGotCaptureHandler KinectRegion.AddHandPointerGotCaptureHandler(btnA, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnB, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnC, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnD, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnE, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnF, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnG, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnH, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnI, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnJ, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnK, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnL, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnM, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnN, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnO, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnP, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnQ, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnR, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnS, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnT, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnU, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnV, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnW, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnX, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnY, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnZ, HandPointerCaptureEvent); KinectRegion.AddHandPointerGotCaptureHandler(btnBackspace, HandPointerCaptureEvent); // 6 - AddHandPointerLostCaptureHandler KinectRegion.AddHandPointerLostCaptureHandler(btnA, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnB, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnC, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnD, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnE, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnF, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnG, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnH, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnI, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnJ, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnK, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnL, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnM, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnN, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnO, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnP, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnQ, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnR, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnS, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnT, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnU, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnV, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnW, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnX, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnY, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnZ, HandPointerLostCaptureEvent); KinectRegion.AddHandPointerLostCaptureHandler(btnBackspace, HandPointerLostCaptureEvent); #endregion }
public static bool CopyBinding(this DependencyObject target, DependencyObject source, DependencyProperty property) { return(source.ReadLocalBinding(property) .Do(b => BindingOperations.SetBinding(target, property, b)) .Return(b => b != null)); }