예제 #1
0
 private static void Register(DataContextBridge bridge)
 {
     if (!registeredBridges.Contains(bridge))
     {
         registeredBridges.Add(bridge);
     }
 }
예제 #2
0
 private static void Unregister(DataContextBridge bridge)
 {
     if (registeredBridges.Contains(bridge))
     {
         registeredBridges.Remove(bridge);
     }
 }
예제 #3
0
        private static void SourceScopeNameChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            string name = e.NewValue as string;

            if (sender is FrameworkElement target && !String.IsNullOrWhiteSpace(name))
            {
                DataContextBridge bridge = registeredBridges.FirstOrDefault(b => b.ScopeName == name);
                if (bridge != null)
                {
                    target.SetBinding(DataContextProperty, new Binding {
                        Source = bridge, Path = new PropertyPath(DataContextProperty), Mode = BindingMode.OneWay
                    });
                }
                else
                {
                    registeredTargets.Add(target);
                }
            }
        }