protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); #if GIVEUP // With ItemsSource="{Binding}" in XAML Binding bind = new Binding(); bind.Source = App.CurrentDisasterList; bind.Mode = BindingMode.OneTime; // You would think oneway would protect App.CurrentDisasterList from changes, but it doesn't EventComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind); #endif //EventComboBox.ItemsSource = App.CurrentDisasterList; //Binding to List is good for unchanging collection. Bind to ObservableCollection if changing. /// No: EventComboBox.DataContext = App.CurrentDisasterList; also crashes: App.CurrentDisasterListForCombo //foreach (TP_EventsDataItem i in App.CurrentDisasterList) // EventComboBox.Items.Add(i); if(App.CurrentDisaster.EventName == "") return; int count = 0; foreach (var i in App.CurrentDisasterList) //TP_EventsDataList.GetEvents()) { if (i.EventName == App.CurrentDisaster.EventName) // Could match instead throughout on EventShortName or EventNumericID { EventListView.SelectedIndex = count; //EventComboBox.SelectedItem = i; break; } count++; } }
/// <summary> /// Create vertex visual control /// </summary> /// <param name="vertexData">Vertex data object</param> /// <param name="bindToDataObject">Bind DataContext to the Vertex data. True by default. </param> public VertexControl(object vertexData, bool bindToDataObject = true) { DefaultStyleKey = typeof (VertexControl); if (bindToDataObject) DataContext = vertexData; Vertex = vertexData; EventOptions = new VertexEventOptions(this); foreach(var item in Enum.GetValues(typeof(EventType)).Cast<EventType>()) UpdateEventhandling(item); IsEnabledChanged += VertexControl_IsEnabledChanged; var xBinding = new Binding { Path = new PropertyPath("(Canvas.Left)"), Source = this }; SetBinding(TestXProperty, xBinding); var yBinding = new Binding { Path = new PropertyPath("(Canvas.Top)"), Source = this }; SetBinding(TestYProperty, yBinding); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { Thickness thick; thick.Top = 400; TextBlock txt = new TextBlock { Text = "Binding This Style in C#", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Margin = thick, FontSize = 60, FontFamily = new FontFamily("Matura MT Script Capitals") }; // Dynamically bind to an existed style. // 1. Setup the source. PropertyPath pPath = new PropertyPath("Foreground"); Binding target = new Binding { ElementName = "topTxt", Path = pPath }; // 2. Bind to the source. It is a DependencyObject, so you must use TextBlock.Foreground instead of Foreground. txt.SetBinding(TextBlock.ForegroundProperty, target); (this.Content as Grid).Children.Add(txt); }
public Room() { TheMainViewModel1 = new MainViewModel(); TheMainViewModel1.fillItems(); thepattern.vec_bs1 = new int[5, 16]; thepattern.vec_bs = new int[80 * 10]; uniformGrid1.Columns = 16; uniformGrid1.Rows = 5; uniformGrid1.ColumnSpacing = 4; uniformGrid1.RowSpacing = 4; uniformGrid1.Orientation = Orientation.Horizontal; uniformGrid1.Visibility = Visibility.Collapsed; for (int i = 0; i < 5; i++) { for (int j = 0; j < 16; j++) { bu[i, j] = new ToggleButton(); clientDict.Add(bu[i, j], new Tuple <int, int>(i, j)); bu[i, j].HorizontalAlignment = HorizontalAlignment.Stretch; bu[i, j].VerticalAlignment = VerticalAlignment.Stretch; uniformGrid1.Children.Add(bu[i, j]); //BINDINGS Toggle_Binding[(j) + (i * 16)] = new Windows.UI.Xaml.Data.Binding(); Toggle_Binding[(j) + (i * 16)].Source = this.TheMainViewModel1; string ppath = "MyItemsbool[" + ((j) + (i * 16)) + "]"; Toggle_Binding[(j) + (i * 16)].Path = new PropertyPath(ppath); Toggle_Binding[(j) + (i * 16)].Mode = BindingMode.TwoWay; Toggle_Binding[(j) + (i * 16)].UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(bu[i, j], ToggleButton.IsCheckedProperty, Toggle_Binding[(j) + (i * 16)]); } } }
public void BindEditor() { Binding b0 = new Binding(); b0.Source = this; b0.Path = new PropertyPath("ItemsSource"); this.SetBinding(ComboBoxEditor.SourceProperty, b0); Binding b1 = new Binding(); b1.Path = new PropertyPath("ValueOptions"); this.SetBinding(ComboBoxEditor.ItemsSourceProperty, b1); Binding b2 = new Windows.UI.Xaml.Data.Binding(); b2.Path = new PropertyPath("Watermark"); this.SetBinding(ComboBoxEditor.PlaceholderTextProperty, b2); Binding b3 = new Binding(); b3.Converter = new BooleanNotConverter(); b3.Path = new PropertyPath("IsReadOnly"); this.SetBinding(ComboBoxEditor.IsEnabledProperty, b3); Binding b4 = new Binding(); b4.Path = new PropertyPath("DisplayMemberPath"); this.SetBinding(ComboBoxEditor.DisplayMemberPathProperty, b4); Binding b5 = new Binding(); b5.Path = new PropertyPath("SelectedValuePath"); this.SetBinding(ComboBoxEditor.SelectedValuePathProperty, b5); }
public static Windows.UI.Xaml.Documents.Run Binding( this Windows.UI.Xaml.Documents.Run element, string property, string propertyPath ) { propertyPath = propertyPath.Replace("].[", "]["); if (property == "Text") { var templateString = "<Run xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Text=\"{{Binding {0}}}\" />"; return((Windows.UI.Xaml.Documents.Run)Windows.UI.Xaml.Markup.XamlReader.Load(templateString.InvariantCultureFormat(propertyPath))); } else { var path = new PropertyPath(propertyPath); var binding = new Windows.UI.Xaml.Data.Binding { Path = path }; var dependencyProperty = GetDependencyProperty(element, property); BindingOperations.SetBinding(element, dependencyProperty, binding); return(element); } }
public static T Binding<T>(this T element, string property, string propertyPath) where T : DependencyObject { var path = new PropertyPath(propertyPath.Replace("].[", "][")); var binding = new Windows.UI.Xaml.Data.Binding { Path = path }; return element.Binding(property, binding); }
public void BindEditor() { Binding b1 = new Binding(); b1.Path = new PropertyPath("ValueOptions"); this.SetBinding(ListEditor.ItemsSourceProperty, b1); Binding b = new Binding() { Mode = BindingMode.TwoWay }; b.Path = new PropertyPath("PropertyValue"); this.SetBinding(ListEditor.SelectedItemProperty, b); Binding b2 = new Windows.UI.Xaml.Data.Binding(); b2.Path = new PropertyPath("Watermark"); this.SetBinding(ListEditor.PlaceholderTextProperty, b2); Binding b3 = new Binding(); b3.Converter = new IsEnabledEditorConvetrer(); b3.Path = new PropertyPath(string.Empty); this.SetBinding(ListEditor.IsEnabledProperty, b3); }
public static sw.FrameworkElementFactory EditableBlock(swd.RelativeSource relativeSource) { var factory = new sw.FrameworkElementFactory(typeof(EditableTextBlock)); var binding = new sw.Data.Binding { Path = TextPath, RelativeSource = relativeSource, Mode = swd.BindingMode.TwoWay, UpdateSourceTrigger = swd.UpdateSourceTrigger.PropertyChanged }; factory.SetBinding(EditableTextBlock.TextProperty, binding); return factory; }
public MainPage() { this.InitializeComponent(); Student stu = new Student { Name = "张三", Course = "C语言" }; // 实例化Binding对象 Windows.UI.Xaml.Data.Binding nameBinding = new Windows.UI.Xaml.Data.Binding(); // 设置源 nameBinding.Source = stu; // 制定获取数据源中的Name属性 nameBinding.Path = new PropertyPath("Name"); Windows.UI.Xaml.Data.Binding courseBinding = new Windows.UI.Xaml.Data.Binding(); courseBinding.Source = stu; courseBinding.Path = new PropertyPath("Course"); // 绑定方向为单向 nameBinding.Mode = courseBinding.Mode = BindingMode.OneWay; // 将 Binding 实例与TextBlock空间的Text属性关联 tbName.SetBinding(TextBlock.TextProperty, nameBinding); tbCourse.SetBinding(TextBlock.TextProperty, courseBinding); TaskItem item = new TaskItem { TaskID = 1000251, TaskName = "示例工序", TaskDesc = "示例描述。", TaskProgress = 60d }; this.layoutRoot.DataContext = item; }
public static object EvalBinding(Windows.UI.Xaml.Data.Binding b) { DummyDO d = new DummyDO(); BindingOperations.SetBinding(d, DummyDO.ValueProperty, b); return(d.Value); }
private static void OnLocationDisplayPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var ctrl = (LocationDisplayToggle)d; if (e.NewValue != null) { Binding b = new Binding() { Source = e.NewValue, Path = new PropertyPath("IsEnabled"), Mode = BindingMode.TwoWay }; ctrl.SetBinding(IsLocationEnabledProperty, b); b = new Binding() { Source = e.NewValue, Path = new PropertyPath("AutoPanMode"), Mode = BindingMode.TwoWay }; ctrl.SetBinding(ModeProperty, b); } else { ctrl.SetBinding(IsLocationEnabledProperty, null); ctrl.SetBinding(ModeProperty, null); } ctrl.UpdateIcon(); }
private static string NativeBindingTest(int count) { var target = new TestModel(); var model = new BindingPerformanceModel(target); var binding = new Windows.UI.Xaml.Data.Binding { Source = model, Mode = BindingMode.TwoWay, Path = new PropertyPath("Property"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(target, TestModel.ValueProperty, binding); Stopwatch startNew = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { target.Value = i % 2 == 0 ? "0" : "1"; } startNew.Stop(); if (model.SetCount != count) { throw new Exception(); } return(startNew.Elapsed.ToString()); }
private void FillPathData(Windows.UI.Xaml.Shapes.Path pathInstance, PathType typeOfPath){ var dataPath = string.Empty ; if (typeOfPath == PathType.Book) { dataPath = "M8.15192985534668,0L8.16493034362793,0 8.16493034362793,39.189998626709C8.16493034362793,39.6419982910156 8.31793022155762,40.0549983978271 8.55592918395996,40.2599983215332 8.79993057250977,40.4699993133545 9.08692932128906,40.4329986572266 9.30992889404297,40.173999786377L15.2389297485352,33.1699991226196 20.8559303283691,40.1579990386963C20.9839305877686,40.3139991760254,21.1359310150146,40.3959999084473,21.2879314422607,40.3959999084473L21.6139316558838,40.2689990997314C21.8609313964844,40.0629997253418,22.0179309844971,39.6469993591309,22.0179309844971,39.189998626709L22.0179309844971,0 52.1599340438843,0C53.090934753418,0,53.8439350128174,0.757999420166016,53.8439350128174,1.6879997253418L53.8439350128174,49.3569984436035C53.8439350128174,50.2879981994629,53.090934753418,51.0459976196289,52.1599340438843,51.0459976196289L52.1399345397949,51.0410003662109C52.0039348602295,51.0699996948242,51.8759346008301,51.0909996032715,51.7449340820313,51.0909996032715L8.14793014526367,51.0909996032715C5.61592864990234,51.0909996032715 3.5399284362793,53.0789985656738 3.39693069458008,55.5789985656738 3.39693069458008,55.7309989929199 3.40092849731445,55.8460006713867 3.40092849731445,55.9209976196289L3.39292907714844,56.0529975891113C3.49493026733398,58.5929985046387,5.58692932128906,60.6279983520508,8.14793014526367,60.6279983520508L50.4719343185425,60.6279983520508 50.4719343185425,55.9669990539551C50.4719343185425,55.0359992980957 51.2299346923828,54.2779998779297 52.1599340438843,54.2779998779297 53.090934753418,54.2779998779297 53.8439350128174,55.0359992980957 53.8439350128174,55.9669990539551L53.8439350128174,62.3120002746582C53.8439350128174,63.246997833252,53.090934753418,64,52.1599340438843,64L7.89292907714844,64 7.63792991638184,63.9749984741211C3.3879280090332,63.7070007324219,0.00792694091796875,60.1749992370605,0.00792694091796875,55.8589973449707L0.0229301452636719,55.5669975280762C-0.0290718078613281,50.5599994659424,0.0229301452636719,12.4609990119934,0.0279273986816406,8.3179988861084L0.0119285583496094,8.14099884033203C0.0119285583496094,3.65299892425537,3.6649284362793,0,8.15192985534668,0z"; } else if (typeOfPath == PathType.Key) { dataPath = "M16.547848,26.872497C14.451092,26.916562 12.365034,27.710413 10.729302,29.266098 7.2240894,32.589393 7.0834706,38.118687 10.403706,41.615683 13.72137,45.118677 19.252512,45.263676 22.752474,41.941881 26.247238,38.621584 26.401036,33.097193 23.078072,29.594298 21.314234,27.73567 18.92417,26.822555 16.547848,26.872497z M47.555126,0.0002117157C47.726013,0.0044841766,47.895291,0.073574066,48.021641,0.20638657L52.778168,5.1985388C53.03077,5.4641666,53.020371,5.888484,52.754769,6.1409225L52.232945,6.6370945 58.379608,13.115402C58.632122,13.382402,58.621121,13.806803,58.354809,14.058203L56.356011,15.956708C56.089798,16.207609,55.665879,16.197409,55.413365,15.930308L49.269745,9.4546347 48.00716,10.655153 52.407509,15.294587C52.660187,15.560289,52.649086,15.984593,52.382813,16.237495L50.384396,18.133013C50.118122,18.386015,49.694359,18.375215,49.441685,18.109612L45.04353,13.473104 30.99349,26.832494 31.170538,27.124847C35.031944,33.685067 34.017586,42.279621 28.253817,47.748075 21.549486,54.107365 10.954499,53.828564 4.5965569,47.125475 -1.7705653,40.417484 -1.4855343,29.826198 5.21898,23.462906 10.672487,18.294763 18.680851,17.507213 24.908787,20.994482L25.088602,21.09812 47.078934,0.18294907C47.211735,0.056484222,47.384236,-0.0040607452,47.555126,0.0002117157z"; } if (!string.IsNullOrEmpty(dataPath)) { var b = new Binding { Source = dataPath }; BindingOperations.SetBinding(pathInstance, Windows.UI.Xaml.Shapes.Path.DataProperty, b); } }
void OnWrapOptionsAppBarButtonClick(object sender, RoutedEventArgs args) { // Create dialog WrapOptionsDialog wrapOptionsDialog = new WrapOptionsDialog { TextWrapping = txtbox.TextWrapping }; // Bind dialog to TextBox Binding binding = new Binding { Source = wrapOptionsDialog, Path = new PropertyPath("TextWrapping"), Mode = BindingMode.TwoWay }; txtbox.SetBinding(TextBox.TextWrappingProperty, binding); // Create popup Popup popup = new Popup { Child = wrapOptionsDialog, IsLightDismissEnabled = true }; // Adjust location based on content size wrapOptionsDialog.SizeChanged += (dialogSender, dialogArgs) => { popup.VerticalOffset = this.ActualHeight - wrapOptionsDialog.ActualHeight - this.BottomAppBar.ActualHeight - 48; popup.HorizontalOffset = 48; }; // Open the popup popup.IsOpen = true; }
private void HandlePlayerControlProgressBarBezzelManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) { ProgressBarScrubView.Visibility = Visibility.Visible; BindingExpression bindingExpression = PlayerControlProgressBarCompleted.GetBindingExpression(Rectangle.WidthProperty); savedWidthBinding = bindingExpression.ParentBinding; }
public FormsListViewItemPresenter() { var verticalContentAlignBinding = new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("VerticalContentAlignment"), RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } }; BindingOperations.SetBinding(this, VerticalContentAlignmentProperty, verticalContentAlignBinding); var paddingBinding = new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("Padding"), RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } }; BindingOperations.SetBinding(this, PaddingProperty, paddingBinding); var contentTransitionBinding = new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("ContentTransitions"), RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } }; BindingOperations.SetBinding(this, ContentTransitionsProperty, contentTransitionBinding); }
private void NavigationMenuPageRenderer_ElementChanged(object sender, VisualElementChangedEventArgs e) { ContainerElement.Loaded += (s, ie) => { var innerGrid = VisualTreeHelper.GetChild(ContainerElement, 0); var grid = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(innerGrid))); var cmdBar = grid.FindChild <FormsCommandBar>("CommandBar"); foreach (AppBarButton cmd in cmdBar.PrimaryCommands) { var toolBarItem = ((FrameworkElement)cmd).DataContext as IconToolbarItem; if (!string.IsNullOrEmpty(toolBarItem.IconGlyph)) { var myBinding = new Windows.UI.Xaml.Data.Binding() { Source = toolBarItem, Path = new PropertyPath(nameof(IconToolbarItem.IconGlyph)), Mode = Windows.UI.Xaml.Data.BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; var icon = new FontIcon() { FontFamily = new FontFamily("Segoe MDL2 Assets"), Glyph = toolBarItem.IconGlyph }; icon.SetBinding(FontIcon.GlyphProperty, myBinding); cmd.Icon = icon; } } }; }
/// <summary> /// Sets a binding from code /// </summary> /// <param name="element"></param> /// <param name="property"></param> /// <param name="source"></param> /// <param name="path"></param> /// <param name="converter"></param> public static void SetBinding(FrameworkElement element, DependencyProperty property, object source, string path, IValueConverter converter = null) { Binding binding = new Binding(); binding.Source = source; binding.Path = new PropertyPath(path); binding.Converter = converter; element.SetBinding(property, binding); }
/// <summary> /// Constructor for the helper. /// </summary> /// <param name="source">Source object that exposes the DependencyProperty you wish to monitor.</param> /// <param name="propertyPath">The name of the property on that object that you want to monitor.</param> public DependencyPropertyChangedHelper(DependencyObject source, string propertyPath) { // Set up a binding that flows changes from the source DependencyProperty through to a DP contained by this helper Binding binding = new Binding { Source = source, Path = new PropertyPath(propertyPath) }; BindingOperations.SetBinding(this, HelperProperty, binding); }
public DependencyPropertyChangedHelper(DependencyObject source, string propertyPath) { Binding binding = new Binding { Source = source, Path = new PropertyPath(propertyPath) }; BindingOperations.SetBinding(this, HelperProperty, binding); }
public NowPlayingBar() { InitializeComponent(); var visBinding = new Binding {Source = DataContext, Path = new PropertyPath("CurrentQueue")}; SetBinding(IsVisibleProperty, visBinding); (App.Locator.CollectionService as CollectionService).PropertyChanged += OnPropertyChanged; }
public static void BindProperty(Control control, object source, string path, DependencyProperty property, BindingMode mode) { var binding = new Binding(); binding.Path = new PropertyPath(path); binding.Source = source; binding.Mode = mode; control.SetBinding(property, binding); }
private void SetVideoPresenters() { var boolToVisConverter = new BooleanToVisibilityConverter(); #if WIN10 var peerSwapChainPanel = new WebRTCSwapChainPanel.WebRTCSwapChainPanel(); var peerHandleBinding = new Binding { Source = DataContext, Path = new PropertyPath("RemoteSwapChainPanelHandle"), Mode = BindingMode.OneWay }; peerSwapChainPanel.SetBinding( WebRTCSwapChainPanel.WebRTCSwapChainPanel.SwapChainPanelHandleProperty, peerHandleBinding); PeerVideoPresenter.Content = peerSwapChainPanel; var selfSwapChainPanel = new WebRTCSwapChainPanel.WebRTCSwapChainPanel(); var selfHandleBinding = new Binding { Source = DataContext, Path = new PropertyPath("LocalSwapChainPanelHandle"), Mode = BindingMode.OneWay }; selfSwapChainPanel.SetBinding( WebRTCSwapChainPanel.WebRTCSwapChainPanel.SwapChainPanelHandleProperty, selfHandleBinding); var selfSizeBinding = new Binding { Source = DataContext, Path = new PropertyPath("LocalNativeVideoSize"), }; selfSwapChainPanel.SetBinding( WebRTCSwapChainPanel.WebRTCSwapChainPanel.SizeProperty, selfSizeBinding); SelfVideoPresenter.Content = selfSwapChainPanel; #endif #if WIN81 _peerMediaElement = new MediaElement { RealTimePlayback = true }; PeerVideoPresenter.Content = _peerMediaElement; _selfMediaElement = new MediaElement { RealTimePlayback = true }; SelfVideoPresenter.Content = _selfMediaElement; #endif }
public static void BindProperty(FrameworkElement element, object source, string path, DependencyProperty property, BindingMode mode) { var binding = new Binding(); binding.Path = new PropertyPath(path); binding.Source = source; binding.Mode = mode; element.SetBinding(property, binding); }
private IList <IMvxUpdateableBinding> GetOrCreateBindingsList(FrameworkElement attachedObject) { var existing = attachedObject.GetValue(BindingsListProperty) as IList <IMvxUpdateableBinding>; if (existing != null) { return(existing); } // attach the list var newList = new List <IMvxUpdateableBinding>(); attachedObject.SetValue(BindingsListProperty, newList); // create a binding watcher for the list #if WINDOWS_WPF var binding = new System.Windows.Data.Binding(); #endif #if WINDOWS_COMMON var binding = new Windows.UI.Xaml.Data.Binding(); #endif bool attached = false; Action attachAction = () => { if (attached) { return; } BindingOperations.SetBinding(attachedObject, DataContextWatcherProperty, binding); attached = true; }; Action detachAction = () => { if (!attached) { return; } #if WINDOWS_COMMON attachedObject.ClearValue(DataContextWatcherProperty); #else BindingOperations.ClearBinding(attachedObject, DataContextWatcherProperty); #endif attached = false; }; attachAction(); attachedObject.Loaded += (o, args) => { attachAction(); }; attachedObject.Unloaded += (o, args) => { detachAction(); }; return(newList); }
public Binding CreateWordHeightBinding() { Binding heightBinding = new Binding() { Path = new PropertyPath("WordHeight"), Source = this }; return heightBinding; }
public Binding CreateWordPositionBinding() { Binding positionBinding = new Binding() { Path = new PropertyPath("WordPosition"), Source = this }; return positionBinding; }
public Binding CreateWordWidthBinding() { Binding widthBinding = new Binding() { Path = new PropertyPath("WordWidth"), Source = this }; return widthBinding; }
public static Binding CreateBinding(INepAppFunctionManager source, string propertyPath, Action <Binding> customizerFunction = null) { Binding binding = new Windows.UI.Xaml.Data.Binding(); binding.Source = source; binding.Path = new PropertyPath(propertyPath); binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; customizerFunction?.Invoke(binding); return(binding); }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { FrameworkElement contentItem = element as FrameworkElement; Binding leftBinding = new Binding() { Path = new PropertyPath("Position.Y") }; Binding topBinding = new Binding() { Path = new PropertyPath("Position.X") }; contentItem.SetBinding(Canvas.LeftProperty, leftBinding); contentItem.SetBinding(Canvas.TopProperty, topBinding); base.PrepareContainerForItemOverride(element, item); }
public static T Binding<T>(this T element, string property, string propertyPath, string converter) where T : IDependencyObjectStoreProvider { var dependencyProperty = GetDependencyProperty(element, property); var path = new PropertyPath(propertyPath.Replace("].[", "][")); var binding = new Windows.UI.Xaml.Data.Binding { Path = path, Converter = ResourceHelper.FindConverter(converter) }; (element as IDependencyObjectStoreProvider).Store.SetBinding(dependencyProperty, binding); return element; }
public static sw.FrameworkElementFactory EditableBlock(swd.RelativeSource relativeSource) { var factory = new sw.FrameworkElementFactory(typeof(EditableTextBlock)); var binding = new sw.Data.Binding { Path = TextPath, RelativeSource = relativeSource, Mode = swd.BindingMode.TwoWay, UpdateSourceTrigger = swd.UpdateSourceTrigger.PropertyChanged }; factory.SetBinding(EditableTextBlock.TextProperty, binding); return(factory); }
//-------------------------- ▶ Constructors public ComponentSelector() { this.DefaultStyleKey = typeof(ComponentSelector); Binding dataContextBinding = new Binding() { Source = App.Current.Resources["Locator"], Path = new PropertyPath("Component") }; this.SetBinding(FrameworkElement.DataContextProperty, dataContextBinding); }
public PageHeader() { this.InitializeComponent(); Binding contentBinding = new Binding { Path = new PropertyPath( "Frame" ), Mode = BindingMode.OneWay }; BindingOperations.SetBinding( this.header, Template10.Controls.PageHeader.FrameProperty, contentBinding ); }
async void ArtistCollectionBase_Loaded(object sender, RoutedEventArgs e) { await Locator.MusicLibraryVM.MusicCollectionLoaded.Task; if (Locator.MusicLibraryVM.Artists.Count > Numbers.SemanticZoomItemCountThreshold) { var b = new Binding(); b.Mode = BindingMode.OneWay; b.Source = this.Resources["GroupArtists"] as CollectionViewSource; ArtistListView.SetBinding(ListView.ItemsSourceProperty, b); SemanticZoom.IsZoomOutButtonEnabled = true; } }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); ListViewItem listViewItem = element as ListViewItem; Binding binding = new Binding(); binding.Mode = BindingMode.TwoWay; binding.Source = item; binding.Path = new PropertyPath("Enabled"); listViewItem.SetBinding(ListViewItem.IsEnabledProperty, binding); listViewItem.SetValue(ListViewItem.FontSizeProperty, 30); }
public DependencyCollectionViewGroupingManagerBase(DependencyCollectionView collectionView) { CollectionView = collectionView; var binding = new Binding { Path = new PropertyPath(nameof(collectionView.IncrementalLoader)), Source = CollectionView }; BindingOperations.SetBinding(this, IncrementalLoaderProperty, binding); }
public static Binding CreateFromDictionary(IDictionary<string, string> dict) { var binding = new Binding(); // Parse the enums first BindingMode mode; if (Enum.TryParse(dict.GetOrDefault("Mode"), out mode)) binding.Mode = mode; RelativeSourceMode sourceMode; if (Enum.TryParse(dict.GetOrDefault("RelativeSource"), out sourceMode)) { binding.RelativeSource = new RelativeSource { Mode = sourceMode }; } UpdateSourceTrigger trigger; if (Enum.TryParse(dict.GetOrDefault("UpdateSourceTrigger"), out trigger)) { binding.UpdateSourceTrigger = trigger; } // Then the other stuff // var converter = SOMETHING; var converterLanguage = dict.GetOrDefault("ConverterLanguage"); var converterParameter = dict.GetOrDefault("ConverterParameter"); var elementName = dict.GetOrDefault("ElementName"); var fallbackValue = dict.GetOrDefault("FallbackValue"); var path = dict.GetOrDefault("Path"); var source = dict.GetOrDefault("Source"); var targetNullValue = dict.GetOrDefault("TargetNullValue"); // And now for the null checks... if (converterLanguage != null) binding.ConverterLanguage = converterLanguage; if (converterParameter != null) binding.ConverterParameter = converterParameter; if (elementName != null) binding.ElementName = elementName; if (fallbackValue != null) binding.FallbackValue = fallbackValue; if (path != null) binding.Path = new PropertyPath(path); if (source != null) binding.Source = source; if (targetNullValue != null) binding.TargetNullValue = targetNullValue; // Done! return binding; }
private void NameTextBlock_OnLoaded(object sender, RoutedEventArgs e) { var trackItem = this.DataContext as TrackItem; var b = new Binding { Converter = App.Current.Resources["CurrentTrackEnhancifierConverter"] as IValueConverter, ConverterParameter = ((TextBlock)sender).Foreground, ConverterLanguage = "color", Source = trackItem, Path = new PropertyPath("IsCurrentPlaying"), }; ((TextBlock)sender).SetBinding(TextBlock.ForegroundProperty, b); }
public MainPage() { this.InitializeComponent(); TraceBinding = new Binding { Mode = BindingMode.OneWay, Path = new PropertyPath("Trace") }; this.SetBinding(TraceProperty, TraceBinding); //redrawTimer = new Timer(RedrawTimerTick, null, 0, 50); }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); var dataItem = item as Category; var uiElement = element as UIElement; var colBinding = new Binding { Source = dataItem, Path = new PropertyPath(ItemColSpanPropertyPath) }; BindingOperations.SetBinding(uiElement, VariableSizedWrapGrid.ColumnSpanProperty, colBinding); var rowBinding = new Binding { Source = dataItem, Path = new PropertyPath(ItemRowSpanPropertyPath) }; BindingOperations.SetBinding(uiElement, VariableSizedWrapGrid.RowSpanProperty, rowBinding); }
public Binding BindCurrentCover(DependencyObject obj, DependencyProperty property) { var myBinding = new Binding { Source = this.transportControls, Path = new PropertyPath(nameof(this.transportControls.CurrentSong) + "." + nameof(this.transportControls.CurrentSong.Thumbnail)), Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(obj, property, myBinding); return(myBinding); }
public Binding BindIsPlaying(DependencyObject obj, DependencyProperty property) { var myBinding = new Binding { Source = this.transportControls, Path = new PropertyPath(nameof(this.transportControls.IsPlaying)), Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(obj, property, myBinding); return(myBinding); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { MyConverterClass myConverter = new MyConverterClass(); PropertyPath p = new PropertyPath("ActualWidth"); Binding b = new Binding { ElementName = "page", Path = p, Converter = myConverter, ConverterParameter = "F7" }; WTxt.SetBinding(TextBlock.TextProperty, b); }
private MediaplayerViewmodel(TransportControls transportControls) { this.transportControls = transportControls; this.mediaPlaybackList = new MediaPlaybackList(); //this.singleRepeatPlaylist = new MediaPlaybackList(); //this._mediaPlaybackList.CurrentItemChanged += this._mediaPlaybackList_CurrentItemChanged; this.transportControls.PlayList = this.mediaPlaybackList; this.currentPlaylist = new ObservableCollection <PlayingSong>(); this.CurrentPlaylist = new ReadOnlyObservableCollection <PlayingSong>(this.currentPlaylist); transportControls.RegisterPropertyChangedCallback(TransportControls.IsShuffledProperty, (sender, e) => { //using (await this.semaphore.Lock()) this.ResetSorting(); }); transportControls.RegisterPropertyChangedCallback(TransportControls.CurrentMediaPlaybackItemProperty, (sender, e) => this.RefresCurrentIndex()); BindToTransportControl(SongProperty, nameof(this.transportControls.CurrentSong)); BindToTransportControl(GoToSettingsCommandProperty, nameof(this.transportControls.GoToSettingsCommand)); BindToTransportControl(GoToNowPlayingCommandProperty, nameof(this.transportControls.GoToNowPlayingCommand)); BindToTransportControl(NextCommandProperty, nameof(this.transportControls.NextCommand)); BindToTransportControl(PreviousCommandProperty, nameof(this.transportControls.PreviousCommand)); BindToTransportControl(PlayCommandProperty, nameof(this.transportControls.PlayCommand)); BindToTransportControl(PauseCommandProperty, nameof(this.transportControls.PauseCommand)); BindToTransportControl(ShuffleCommandProperty, nameof(this.transportControls.ShuffleCommand)); BindToTransportControl(RepeateCommandProperty, nameof(this.transportControls.RepeateCommand)); BindToTransportControl(IsShuffledProperty, nameof(this.transportControls.IsRepeate)); BindToTransportControl(IsRepeateProperty, nameof(this.transportControls.IsShuffled)); BindToTransportControl(IsPlayingProperty, nameof(this.transportControls.IsPlaying)); //return myBinding; void BindToTransportControl(DependencyProperty songProperty, string Path) { var myBinding = new Binding { Source = this.transportControls, Path = new PropertyPath(Path), Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(this, songProperty, myBinding); } }
void WatchForContentChanges() { // If the content of the command bar changes while it's collapsed, we need to // react and update the visibility (e.g., if the bar is placed at the bottom and // has no commands, then is moved to the top and now includes the title) // There's no event on CommandBar when the content changes, so we'll bind our own // dependency property to Content and update our visibility when it changes var binding = new Windows.UI.Xaml.Data.Binding { Source = this, Path = new PropertyPath(nameof(Content)), Mode = Windows.UI.Xaml.Data.BindingMode.OneWay }; BindingOperations.SetBinding(this, s_contentChangeWatcher, binding); }
public static void ApplyBinding(FrameworkElement source, FrameworkElement target, string propertyPath, DependencyProperty property, IValueConverter converter = null, object converterParameter = null) { if (source == null || target == null) { return; } #if WINDOWS_STORE || WINDOWS_PHONE_APP var binding = new Windows.UI.Xaml.Data.Binding(); #elif WINDOWS_PHONE var binding = new System.Windows.Data.Binding(); #endif binding.Source = source; binding.Path = new PropertyPath(propertyPath); binding.Converter = converter; binding.ConverterParameter = converterParameter; target.SetBinding(property, binding); }
void SetSelectedVisual(FrameworkElement element) { // Find all labels in children and set their foreground color to accent color IEnumerable <FrameworkElement> elementsToHighlight = FindPhoneHighlights(element); var systemAccentBrush = (Brush)WApp.Current.Resources["SystemColorControlAccentBrush"]; foreach (FrameworkElement toHighlight in elementsToHighlight) { Brush brush = null; WBinding binding = toHighlight.GetForegroundBinding(); if (binding == null) { brush = toHighlight.GetForeground(); } var brushedElement = new BrushedElement(toHighlight, binding, brush); _highlightedElements.Add(brushedElement); toHighlight.SetForeground(systemAccentBrush); } }
protected virtual void ApplyBinding(MvxBindingDescription bindingDescription, Type actualType, FrameworkElement attachedObject) { DependencyProperty dependencyProperty = actualType.FindDependencyProperty(bindingDescription.TargetName); if (dependencyProperty == null) { MvxLogHost.GetLog <MvxWindowsBindingCreator>()?.Log(LogLevel.Warning, "Dependency property not found for {targetName}", bindingDescription.TargetName); return; } var property = actualType.FindActualProperty(bindingDescription.TargetName); if (property == null) { MvxLogHost.GetLog <MvxWindowsBindingCreator>()?.Log(LogLevel.Warning, "Property not returned for target {targetName} - may cause issues", bindingDescription.TargetName); } var sourceStep = bindingDescription.Source as MvxPathSourceStepDescription; if (sourceStep == null) { MvxLogHost.GetLog <MvxWindowsBindingCreator>()?.Log(LogLevel.Warning, "Binding description for {targetName} is not a simple path - Windows Binding cannot cope with this", bindingDescription.TargetName); return; } var newBinding = new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath(sourceStep.SourcePropertyPath), Mode = ConvertMode(bindingDescription.Mode, property?.PropertyType ?? typeof(object)), Converter = GetConverter(sourceStep.Converter), ConverterParameter = sourceStep.ConverterParameter, FallbackValue = sourceStep.FallbackValue }; BindingOperations.SetBinding(attachedObject, dependencyProperty, newBinding); }
private void CreateOneWayToSourceBinding() { switch (UpdateSourceTrigger) { case UpdateSourceTrigger.Default: case UpdateSourceTrigger.PropertyChanged: using (DisableableTargetPropertyValueChangedCallback.Disable()) { var binding = new Windows.UI.Xaml.Data.Binding { Source = this, Path = new PropertyPath(TargetPropertyValuePropertyName), Mode = BindingMode.TwoWay }; BindingOperations.SetBinding(_associatedObject, _dependencyPropertyDescriptor.DependencyProperty, binding); } break; case UpdateSourceTrigger.Explicit: break; default: throw new InvalidOperationException("Unknown UpdateSourceTrigger mode."); } }
private void SetSourcePropertyBinding(bool shouldRaiseOnSourcePropertyValueChanged) { var binding = new Windows.UI.Xaml.Data.Binding { Converter = Converter, ConverterLanguage = ConverterLanguage, ConverterParameter = ConverterParameter, ElementName = ElementName, FallbackValue = FallbackValue, Mode = Mode, Path = Path, RelativeSource = RelativeSource, Source = Source, UpdateSourceTrigger = UpdateSourceTrigger, TargetNullValue = TargetNullValue }; using (DisableableSourceValueChangedCallback.Disable()) { BindingOperations.SetBinding(this, SourcePropertyValueProperty, binding); } if (shouldRaiseOnSourcePropertyValueChanged) { OnSourcePropertyValueChanged(); } }
private void UwpListViewNative_ChildChanged(object sender, EventArgs e) { // Example of getting binding working through code behind if (sender.GetType() == typeof(Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost)) { var host = ((Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost)sender); if (host.Child != null && host.Child.GetType() == typeof(Windows.UI.Xaml.Controls.ListView)) { var CalView = ((Windows.UI.Xaml.Controls.ListView)host.Child); CalView.DataContext = this.DataContext; var myBinding = new Windows.UI.Xaml.Data.Binding() { Path = new Windows.UI.Xaml.PropertyPath("RandomColItems") }; Windows.UI.Xaml.Data.BindingOperations.SetBinding(CalView, Windows.UI.Xaml.Controls.ListView.ItemsSourceProperty, myBinding); } } }
public BrushedElement(FrameworkElement element, WBinding brushBinding = null, Brush brush = null) { Element = element; BrushBinding = brushBinding; Brush = brush; }
private async void GenerateControls(PropertyInfo property, PropertyInfo parentProperty) { var label = GenerateLabelPropertyName(property); var propertyType = property.PropertyType; var tColl = typeof(ICollection <>); if (propertyType.GetTypeInfo().IsGenericType&& tColl.IsAssignableFrom(propertyType.GetGenericTypeDefinition()) || propertyType.GetInterfaces().Any(x => x.GetTypeInfo().IsGenericType&& x.GetGenericTypeDefinition() == tColl)) { var selectedItemAttribute = Helpers.AttributeHelper <SelectedItemCollectionAttribute> .GetAttributeValue(property); if (selectedItemAttribute != null) { var binding2 = new Windows.UI.Xaml.Data.Binding(); var memberPath = string.Empty; var displayMemberPathAttribute = Helpers.AttributeHelper <DisplayMemberPathCollectionAttribute> .GetAttributeValue(property); if (displayMemberPathAttribute != null) { memberPath = displayMemberPathAttribute.DisplayMemberPath; } if (!string.IsNullOrEmpty(memberPath)) { memberPath = "." + memberPath; } if (parentProperty != null) { binding2.Path = new PropertyPath((parentProperty.Name + "." + selectedItemAttribute.PropertyNameToBind + memberPath).Trim()); } else { binding2.Path = new PropertyPath((selectedItemAttribute.PropertyNameToBind + memberPath).Trim()); } binding2.Source = this.DataContext; binding2.Mode = BindingMode.TwoWay; binding2.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; // binding2.NotifyOnValidationError = true; var num = new TextBlock(); num.Margin = new Thickness(0, 8, 0, 8); num.FontSize = this.PropertyTextFontSize; num.FontWeight = this.PropertyTextWeight; var foregroundBinding = new Binding(); foregroundBinding.Source = this; foregroundBinding.Mode = BindingMode.TwoWay; foregroundBinding.Path = new PropertyPath("ForegroundText"); num.SetBinding(TextBlock.ForegroundProperty, foregroundBinding); num.SetBinding(TextBlock.TextProperty, binding2); stack.Children.Add(label); stack.Children.Add(num); } } else { if (propertyType.Equals(typeof(bool)) || propertyType.Equals(typeof(Nullable <bool>))) { var text = GeneratePropertyBinding(property, parentProperty, true); stack.Children.Add(label); stack.Children.Add(text); } else { var text = GeneratePropertyBinding(property, parentProperty); stack.Children.Add(label); stack.Children.Add(text); } } //var propertyType = property.PropertyType; //if (propertyType.Equals(typeof(int)) || // propertyType.Equals(typeof(long)) || // propertyType.Equals(typeof(Nullable<int>)) || // propertyType.Equals(typeof(Nullable<long>))) //{ // await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => // { // var isNumeric = Helpers.AttributeHelper<IsNumericAttribute>.GetAttributeValue(property); // if (isNumeric != null) // { // GenerateNumericUpDown(property, parentProperty); // } // else // { // GenerateTextBox(property, parentProperty); // } // }); // return; //} //if (propertyType.Equals(typeof(string))) //{ // await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => // { // var isSuggestionsEnabled = Helpers.AttributeHelper<IsSuggestionsEnabledAttribute>.GetAttributeValue(property); // if (isSuggestionsEnabled != null) // { // GenerateSuggestionsControl(property, parentProperty); // } // else // { // GenerateTextBox(property, parentProperty); // } // }); // return; //} //if (propertyType.Equals(typeof(float)) || // propertyType.Equals(typeof(decimal)) || // propertyType.Equals(typeof(double)) || // propertyType.Equals(typeof(Nullable<double>)) || // propertyType.Equals(typeof(Nullable<decimal>)) || // propertyType.Equals(typeof(Nullable<float>)) //) //{ // await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => // { // GenerateNumericUpDown(property, parentProperty); // }); // return; //} //if (propertyType.Equals(typeof(DateTime)) || propertyType.Equals(typeof(Nullable<DateTime>))) //{ // await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => // { // GenerateDatePicker(property, parentProperty); // }); // return; //} //if (propertyType.Equals(typeof(bool)) || propertyType.Equals(typeof(Nullable<bool>))) //{ // await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => // { // GenerateCheckBox(property, parentProperty); // }); // return; //} //if (propertyType.Equals(typeof(TimeSpan)) || propertyType.Equals(typeof(Nullable<TimeSpan>))) //{ // await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => // { // GenerateDateTimePicker(property, parentProperty); // }); // return; //} }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); this.Loaded += GridViewEx_Loaded; this.SizeChanged += (s, ee) => { _itemsWrapGrid = this.GetFirstDescendantOfType <ItemsWrapGrid>(); if (_itemsWrapGrid == null) { return; } int colum = (int)Math.Floor(ee.NewSize.Width / this.ItemWidthSuggest); _itemsWrapGrid.ItemWidth = ee.NewSize.Width / colum; if (colum > 1) { this.ItemContainerStyle = (this.GetTemplateChild("RootLayout") as Grid).Resources["GridViewItemStyle2"] as Style; } else { this.ItemContainerStyle = (this.GetTemplateChild("RootLayout") as Grid).Resources["GridViewItemStyle1"] as Style; } }; if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { return; } _scrollViewer = this.GetFirstDescendantOfType <ScrollViewer>(); var binding = new Windows.UI.Xaml.Data.Binding { Source = _scrollViewer, Path = new PropertyPath("VerticalOffset") }; BindingOperations.SetBinding(this, VerticalOffsetProperty, binding); _refreshIcon = this.GetTemplateChild("RefreshIcon") as SymbolIcon; _scrollViewer.DirectManipulationStarted += OnDirectManipulationStarted; _scrollViewer.DirectManipulationCompleted += OnDirectManipulationCompleted; _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); var compositor = _scrollerViewerManipulation.Compositor; // At the moment there are three things happening when pulling down the list - // 1. The Refresh Icon fades in. // 2. The Refresh Icon rotates (400°). // 3. The Refresh Icon gets pulled down a bit (REFRESH_ICON_MAX_OFFSET_Y) // QUESTION 5 // Can we also have Geometric Path animation so we can also draw the Refresh Icon along the way? // // Create a rotation expression animation based on the overpan distance of the ScrollViewer. _rotationAnimation = compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) * Multiplier, MaxDegree)"); _rotationAnimation.SetScalarParameter("Multiplier", 10.0f); _rotationAnimation.SetScalarParameter("MaxDegree", 400.0f); _rotationAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create an opacity expression animation based on the overpan distance of the ScrollViewer. _opacityAnimation = compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)"); _opacityAnimation.SetScalarParameter("Divider", 30.0f); _opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create an offset expression animation based on the overpan distance of the ScrollViewer. _offsetAnimation = compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)) * MaxOffsetY"); _offsetAnimation.SetScalarParameter("Divider", 30.0f); _offsetAnimation.SetScalarParameter("MaxOffsetY", REFRESH_ICON_MAX_OFFSET_Y); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Get the RefreshIcon's Visual. _refreshIconVisual = ElementCompositionPreview.GetElementVisual(_refreshIcon); // Set the center point for the rotation animation //if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled) //{ // _refreshIconVisual.CenterPoint = new Vector3(Convert.ToSingle(_refreshIcon.Width / 2), Convert.ToSingle(_refreshIcon.Height / 2), 0); //} // Kick off the animations. _refreshIconVisual.StartAnimation("RotationAngleInDegrees", _rotationAnimation); _refreshIconVisual.StartAnimation("Opacity", _opacityAnimation); _refreshIconVisual.StartAnimation("Offset.Y", _offsetAnimation); this.Unloaded += (s, e) => { _scrollViewer.DirectManipulationStarted -= OnDirectManipulationStarted; _scrollViewer.DirectManipulationCompleted -= OnDirectManipulationCompleted; }; //加速度计,摇一摇 //_accelerometer = Accelerometer.GetDefault(); //if (_accelerometer != null) //{ // // Establish the report interval // uint minReportInterval = _accelerometer.MinimumReportInterval; // uint reportInterval = minReportInterval > 16 ? minReportInterval : 16; // _accelerometer.ReportInterval = reportInterval; // // Assign an event handler for the reading-changed event // _accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged); //} }