当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkElement.SetValue方法代码示例

本文整理汇总了C#中FrameworkElement.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.SetValue方法的具体用法?C# FrameworkElement.SetValue怎么用?C# FrameworkElement.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FrameworkElement的用法示例。


在下文中一共展示了FrameworkElement.SetValue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOrCreateBindingsList

        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_PHONE || WINDOWS_WPF
            var binding = new System.Windows.Data.Binding();
#endif
#if NETFX_CORE
            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_PHONE || NETFX_CORE
                    attachedObject.ClearValue(DataContextWatcherProperty);
#else
                    BindingOperations.ClearBinding(attachedObject, DataContextWatcherProperty);
#endif
                    attached = false;
                };
            attachAction();
            attachedObject.Loaded += (o, args) =>
            {
                attachAction();
            };
            attachedObject.Unloaded += (o, args) =>
            {
                detachAction();
            };

            return newList;
        }
开发者ID:indazoo,项目名称:MvvmCross_DesignData,代码行数:48,代码来源:MvxMvvmCrossBindingCreator.cs

示例2: SetOpen

        public static void SetOpen(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(OpenProperty, animationDefinition);

            if (animationDefinition.OpacityFromZero)
                element.Opacity = 0;

            element.Loaded += async (sender, args) =>
            {
                var idleDefinition = GetIdle(element);
                if (idleDefinition == null)
                {
                    await element.AnimateAsync(animationDefinition);
                }
            };
        }
开发者ID:uwper,项目名称:AnimationManager,代码行数:16,代码来源:AnimationTrigger.cs

示例3: InitializeBusyIndicator

        partial void InitializeBusyIndicator()
        {
            if (_busyIndicator != null)
            {
                return;
            }

            _grid = new Grid();
            _grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1, GridUnitType.Star)});
            _grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1, GridUnitType.Auto)});
            _grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1, GridUnitType.Auto)});
            _grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1, GridUnitType.Star)});

            var backgroundBorder = new Border();
            backgroundBorder.Background = new SolidColorBrush(Colors.Gray);
            backgroundBorder.Opacity = 0.5;
            backgroundBorder.SetValue(Grid.RowSpanProperty, 4);
            _grid.Children.Add(backgroundBorder);

            _statusTextBlock = new TextBlock();
            //_statusTextBlock.Style = (Style)Application.Current.Resources["PhoneTextNormalStyle"];
            _statusTextBlock.HorizontalAlignment = HorizontalAlignment.Center;
            _statusTextBlock.SetValue(Grid.RowProperty, 1);
            _grid.Children.Add(_statusTextBlock);

            _busyIndicator = ConstructorBusyIndicator();
            _busyIndicator.SetValue(Grid.RowProperty, 2);
            _grid.Children.Add(_busyIndicator);

            _containerPopup = new Popup();
            _containerPopup.VerticalAlignment = VerticalAlignment.Center;
            _containerPopup.HorizontalAlignment = HorizontalAlignment.Center;
            _containerPopup.Child = _grid;

            double rootWidth = Window.Current.Bounds.Width;
            double rootHeight = Window.Current.Bounds.Height;

            _busyIndicator.Width = rootWidth;

            _grid.Width = rootWidth;
            _grid.Height = rootHeight;

            _containerPopup.UpdateLayout();
        }
开发者ID:matthijskoopman,项目名称:Catel,代码行数:44,代码来源:PleaseWaitService.winrt.cs

示例4: SetClose

        public static void SetClose(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(CloseProperty, animationDefinition);

            element.Loaded += (sender, args) =>
            {
                lock (_lockObject)
                {
                    CloseElements.Add(element);
                }
            };
            element.Unloaded += (sender, args) =>
            {
                lock (_lockObject)
                {
                    CloseElements.Remove(element);
                }
            };
        }
开发者ID:uwper,项目名称:AnimationManager,代码行数:19,代码来源:AnimationTrigger.cs

示例5: SetIdle

        public static void SetIdle(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(IdleProperty, animationDefinition);
            element.Loaded += async (sender, args) =>
            {
                var openAnimation = GetOpen(element);
                if (openAnimation != null)
                {
                    if (openAnimation.OpacityFromZero)
                        element.Opacity = 0;

                    await element.AnimateAsync(openAnimation);
                }

                animationDefinition.Forever = true;
                await element.AnimateAsync(animationDefinition);
            };

        }
开发者ID:uwper,项目名称:AnimationManager,代码行数:19,代码来源:AnimationTrigger.cs

示例6: ExecuteOnFirstLoad

 /// <summary>
 /// Executes the handler the fist time the element is loaded.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="handler">The handler.</param>
 public static void ExecuteOnFirstLoad(FrameworkElement element, Action<FrameworkElement> handler)
 {
     if ((bool) element.GetValue(PreviouslyAttachedProperty)) return;
     element.SetValue(PreviouslyAttachedProperty, true);
     ExecuteOnLoad(element, handler);
 }
开发者ID:belyansky,项目名称:Caliburn.Light,代码行数:11,代码来源:ViewHelper.cs

示例7: ExecuteOnLoad

        /// <summary>
        /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        /// <returns>true if the handler was executed immediately; false otherwise</returns>
        public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler handler)
        {
#if SILVERLIGHT
            if ((bool)element.GetValue(IsLoadedProperty))
#elif WinRT
            if (IsElementLoaded(element))
#else
            if(element.IsLoaded)
#endif
            {
                handler(element, new RoutedEventArgs());
                return true;
            }
            else
            {
                RoutedEventHandler loaded = null;
                loaded = (s, e) =>
                {
#if SILVERLIGHT
                    element.SetValue(IsLoadedProperty, true);
#endif
                    handler(s, e);
                    element.Loaded -= loaded;
                };

                element.Loaded += loaded;
                return false;
            }
        }
开发者ID:yan122725529,项目名称:SqlComPare_Mvvm,代码行数:35,代码来源:View.cs

示例8: ParseMetadata

        /// <summary>
        /// Parse metadata from a target FrameworkElement.  This will cache the metadata on the element as an attached property.
        /// </summary>
        /// <param name="element">The target FrameworkElement to pull metadata from.</param>
        /// <param name="forceUpdate">If set, will not pull metadata from cache.</param>
        /// <param name="entity">The entity used.</param>
        /// <param name="bindingExpression">The bindingExpression used.</param>
        /// <returns>Returns the metadata associated with the element.  Will be null if no metadata was found.</returns>
        internal static ValidationMetadata ParseMetadata(FrameworkElement element, bool forceUpdate, out object entity, out BindingExpression bindingExpression)
        {
            entity = null;
            bindingExpression = null;
            if (element == null)
            {
                return null;
            }

            if (!forceUpdate)
            {
                ValidationMetadata existingVMD = element.GetValue(ValidationMetadataProperty) as ValidationMetadata;
                if (existingVMD != null)
                {
                    return existingVMD;
                }
            }

            BindingExpression be = null;
            FieldInfo[] fields = element.GetType().GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
            foreach (FieldInfo field in fields)
            {
                if (field.FieldType == typeof(DependencyProperty))
                {
                    // Found a dependency property
                    be = element.GetBindingExpression((DependencyProperty)field.GetValue(null));
                    if (be != null && be.ParentBinding != null && be.ParentBinding.Path != null)
                    {
                        // Found a BindingExpression, ensure it has valid data
                        entity = be.DataItem != null ? be.DataItem : element.DataContext;
                        if (entity != null)
                        {
                            if (be.ParentBinding.Mode == BindingMode.TwoWay)
                            {
                                bindingExpression = be;
                                // A twoway binding will be automatically chosen and the rest ignored
                                break;
                            }

                            // Perform an arbitrary sort on path (string), so the same dependency property is chosen consistently.
                            // Reflection ordering is not deterministic and if we just pick the first, we could be
                            // matched with different dependency properties depending on the run.
                            if (bindingExpression == null || string.Compare(be.ParentBinding.Path.Path, bindingExpression.ParentBinding.Path.Path, StringComparison.Ordinal) < 0)
                            {
                                bindingExpression = be;
                            }
                        }
                    }
                }
            }
            if (bindingExpression != null)
            {
                ValidationMetadata newVMD = ParseMetadata(bindingExpression.ParentBinding.Path.Path, entity);
                element.SetValue(ValidationMetadataProperty, newVMD);
                return newVMD;
            }
            return null;
        }
开发者ID:expanz,项目名称:expanz-Microsoft-XAML-SDKs,代码行数:66,代码来源:ValidationHelper.cs

示例9: SetTextHintingMode

		public static void SetTextHintingMode (FrameworkElement target, TextHintingMode textHintingMode)
		{
			target.SetValue (TextOptions.TextHintingModeProperty, textHintingMode);
		}
开发者ID:dfr0,项目名称:moon,代码行数:4,代码来源:TextOptions.cs

示例10: SetIsHeaderOf

 public static void SetIsHeaderOf(FrameworkElement element, TreeViewItem value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(IsHeaderOfProperty, value);
 }
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:8,代码来源:TreeViewConnectingLines.cs

示例11: TextEditor

        //----------------------------------------------------- 
        //
        //  Constructors 
        // 
        //-----------------------------------------------------
 
        #region Constructors

        /// <summary>
        /// Initialize the TextEditor 
        /// </summary>
        /// <param name="textContainer"> 
        /// TextContainer representing a content to edit. 
        /// </param>
        /// <param name="uiScope"> 
        /// FrameworkElement on which all events for the user interaction will be
        /// processed.
        /// </param>
        /// <param name="isUndoEnabled"> 
        /// If true the TextEditor will enable undo support
        /// </param> 
        internal TextEditor(ITextContainer textContainer, FrameworkElement uiScope, bool isUndoEnabled) 
        {
            // Validate parameters 
            Invariant.Assert(uiScope != null);

            // Set non-zero property defaults.
            _acceptsRichContent = true; 

            // Attach the editor  instance to the scope 
            _textContainer = textContainer; 
            _uiScope = uiScope;
 
            // Enable undo manager for this uiScope
            if (isUndoEnabled && _textContainer is TextContainer)
            {
                ((TextContainer)_textContainer).EnableUndo(_uiScope); 
            }
 
            // Create TextSelection and link it to text container 
            _selection = new TextSelection(this);
            textContainer.TextSelection = _selection; 

            // Create DragDropProcess
            //
 
            _dragDropProcess = new TextEditorDragDrop._DragDropProcess(this);
 
            // By default we use IBeam cursor 
            _cursor = Cursors.IBeam;
 
            // Add InputLanguageChanged event handler
            TextEditorTyping._AddInputLanguageChangedEventHandler(this);

            // Listen to both TextContainer.EndChanging and TextContainer.Changed events 
            TextContainer.Changed += new TextContainerChangedEventHandler(OnTextContainerChanged);
 
            // Add IsEnabled event handler for cleaning the caret element when uiScope is disabled 
            _uiScope.IsEnabledChanged += new DependencyPropertyChangedEventHandler(OnIsEnabledChanged);
 
            // Attach this instance of text editor to its uiScope
            _uiScope.SetValue(TextEditor.InstanceProperty, this);

            // The IsSpellerEnabled property might have been set before this 
            // TextEditor was instantiated -- check if we need to rev
            // up speller support. 
            if ((bool)_uiScope.GetValue(SpellCheck.IsEnabledProperty)) 
            {
                SetSpellCheckEnabled(true); 
                SetCustomDictionaries(true);
            }

            // If no IME/TextServices are installed, we have no native reasources 
            // to clean up at Finalizer.
            if (!TextServicesLoader.ServicesInstalled) 
            { 
                GC.SuppressFinalize(this);
            } 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:79,代码来源:TextEditor.cs

示例12: SetPropertyBinding

 public static void SetPropertyBinding(FrameworkElement element, SetterValueBindingHelper value)
 {
     if (null == element)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(PropertyBindingProperty, value);
 }
开发者ID:modulexcite,项目名称:WizardControl-UWP,代码行数:8,代码来源:SetterValueBindingHelper.cs

示例13: SuspendScroll

		private static void SuspendScroll(object sender, RoutedEventArgs e)
		{
            
			var blockingElement = sender as FrameworkElement;

			// Determines the parent Panorama/Pivot control
			if (_internalPanningControl == null)
#if WINDOWS_STORE
                _internalPanningControl = FindAncestor(blockingElement, p => p is Hub || p is FlipView) as FrameworkElement;
#elif WINDOWS_PHONE_APP
                _internalPanningControl = FindAncestor(blockingElement, p => p is Pivot || p is Hub || p is FlipView) as FrameworkElement;
#elif WINDOWS_PHONE
                _internalPanningControl = FindAncestor(blockingElement, p => p is Pivot || p is Panorama) as FrameworkElement;
#endif

			if (_internalPanningControl != null && (bool)_internalPanningControl.GetValue(IsScrollSuspendedProperty))
				return;
			// When the user touches the control...
			var originalSource = e.OriginalSource as DependencyObject;
			if (FindAncestor(originalSource, dobj => (dobj == blockingElement)) != blockingElement)
				return;

			// Mark the parent Panorama/Pivot for scroll suspension
			// and register for touch frame events
			if (_internalPanningControl != null)
				_internalPanningControl.SetValue(IsScrollSuspendedProperty, true);

#if WINDOWS_STORE || WINDOWS_PHONE_APP
            CoreWindow.GetForCurrentThread().PointerReleased += PreventScrollBinding_PointerReleased;
#elif WINDOWS_PHONE
            Touch.FrameReported += TouchFrameReported;
#endif
			if (blockingElement != null)
				blockingElement.IsHitTestVisible = true;

			if (_internalPanningControl != null)
				_internalPanningControl.IsHitTestVisible = false;
		}
开发者ID:selaromdotnet,项目名称:Coding4FunToolkit,代码行数:38,代码来源:PreventScrollBinding.cs


注:本文中的FrameworkElement.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。