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


C# FrameworkElement.FindName方法代码示例

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


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

示例1: DoLookups

		private void DoLookups (FrameworkElement elem)
		{
			debug_panel.Children.Add (new TextBlock () { Text =  String.Format ("Lookups from {0} ({1})", elem.Name, elem) });

			debug_panel.Children.Add (new TextBlock () { Text = String.Format ("{0}.my_canvas: {1}", elem, elem.FindName ("my_canvas")) });
			debug_panel.Children.Add (new TextBlock () { Text = String.Format ("{0}.sub_element: {1}", elem, elem.FindName ("sub_element")) });
			debug_panel.Children.Add (new TextBlock () { Text = String.Format ("{0}.component_element: {1}", elem, elem.FindName ("component_element")) });
			debug_panel.Children.Add (new Canvas () { Height = 20 });
		}
开发者ID:dfr0,项目名称:moon,代码行数:9,代码来源:Page.xaml.cs

示例2: SetDataContext

        internal static void SetDataContext( this DependencyObject source, DependencyProperty property, FrameworkElement element )
        {
            Contract.Requires( source != null );
            Contract.Requires( property != null );

            // if there's no context that can be used to for updating, there's no sense in continuing
            if ( element == null || element.DataContext == null )
                return;

            // get the data binding expression
            var expression = source.ReadLocalValue( property ) as BindingExpression;

            // if there's no expression, then parameter isn't data bound
            if ( expression == null || expression.ParentBinding == null )
                return;

            var currentBinding = expression.ParentBinding;

            // skip one-time or relative source bindings
            if ( currentBinding.Mode == BindingMode.OneTime || currentBinding.RelativeSource != null )
                return;

            // clone current binding and set source to data context of associated object
            var binding = currentBinding.Clone();

            if ( !string.IsNullOrEmpty( binding.ElementName ) )
                binding.Source = element.FindName( binding.ElementName ) ?? element.DataContext;
            else
                binding.Source = element.DataContext;

            // update binding
            BindingOperations.SetBinding( source, property, binding );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:33,代码来源:DependencyPropertyExtensions.cs

示例3: FindFrame

        /// <summary>
        /// Finds the frame identified with given name in the specified context.
        /// </summary>
        /// <param name="name">The frame name.</param>
        /// <param name="context">The framework element providing the context for finding a frame.</param>
        /// <returns>The frame or null if the frame could not be found.</returns>
        public static ModernFrame FindFrame(string name, FrameworkElement context) {
            if (context == null) {
                throw new ArgumentNullException(nameof(context));
            }

            // collect all ancestor frames
            var frames = context.AncestorsAndSelf().OfType<ModernFrame>().ToArray();

            switch (name) {
                case null:
                case FrameSelf:
                    // find first ancestor frame
                    return frames.FirstOrDefault();
                case FrameParent:
                    // find parent frame
                    return frames.Skip(1).FirstOrDefault();
                case FrameTop:
                    // find top-most frame
                    return frames.LastOrDefault();
            }

            // find ancestor frame having a name matching the target
            var frame = frames.FirstOrDefault(f => f.Name == name);
            if (frame != null) return frame;

            // find frame in context scope
            frame = context.FindName(name) as ModernFrame;
            if (frame != null) return frame;

            // find frame in scope of ancestor frame content
            var parent = frames.FirstOrDefault();
            var content = parent?.Content as FrameworkElement;
            return content?.FindName(name) as ModernFrame;
        }
开发者ID:gro-ove,项目名称:actools,代码行数:40,代码来源:NavigationHelper.cs

示例4: GetBoundMember

 public static object GetBoundMember(FrameworkElement element, string name) {
     object result = element.FindName(name);
     if (result == null) {
         return OperationFailed.Value;
     }
     return result;
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:ExtensionTypes.cs

示例5: GetValue

        /// <internalonly />
        public override object GetValue(FrameworkElement element)
        {
            if (String.IsNullOrEmpty(_propertyName)) {
                throw new InvalidOperationException("The PropertyName on an ElementProperty must be specified.");
            }

            object source = null;

            if (String.IsNullOrEmpty(_elementName)) {
                source = element.DataContext;
            }
            else if (String.CompareOrdinal(_elementName, "$self") == 0) {
                source = element;
            }
            else {
                source = element.FindName(_elementName);
            }

            if (source == null) {
                throw new InvalidOperationException("The ElementProperty could not find the specified element to use as the source of its value.");
            }

            PropertyInfo sourceProperty = source.GetType().GetProperty(_propertyName);
            if (sourceProperty == null) {
                throw new InvalidOperationException("The specified property '" + _propertyName + "' was not found on an object of type '" + source.GetType().FullName + "'");
            }

            return sourceProperty.GetValue(source, null);
        }
开发者ID:ssssyin,项目名称:silverlightfx,代码行数:30,代码来源:ElementProperty.cs

示例6: ToolTipHelper

        public ToolTipHelper(FrameworkElement panel)
        {
            this.panel = panel;

            InitStatusMap();
            //TooltipControl tooltip = new TooltipControl();
            Grid rootView =  panel.FindName("root") as Grid;
            rootView.Children.Add(tooltip);
            tooltip.registerObserver(this);

            panel.PreviewMouseUp +=new MouseButtonEventHandler(panel_PreviewMouseUp);
            tooltip.MouseUp +=new MouseButtonEventHandler(tooltip_MouseUp);
        }
开发者ID:junzheng,项目名称:YF17A,代码行数:13,代码来源:ToolTipHelper.cs

示例7: FindFrame

        /// <summary>
        /// Finds the frame identified with given name in the specified context.
        /// </summary>
        /// <param name="name">The frame name.</param>
        /// <param name="context">The framework element providing the context for finding a frame.</param>
        /// <returns>The frame or null if the frame could not be found.</returns>
        public static ModernFrame FindFrame(string name, FrameworkElement context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // collect all ancestor frames
            var frames = context.AncestorsAndSelf().OfType<ModernFrame>().ToArray();

            if (name == null || name == FrameSelf)
            {
                // find first ancestor frame
                return frames.FirstOrDefault();
            }
            if (name == FrameParent)
            {
                // find parent frame
                return frames.Skip(1).FirstOrDefault();
            }
            if (name == FrameTop)
            {
                // find top-most frame
                return frames.LastOrDefault();
            }

            // find ancestor frame having a name matching the target
            var frame = frames.FirstOrDefault(f => f.Name == name);

            if (frame == null)
            {
                // find frame in context scope
                frame = context.FindName(name) as ModernFrame;

                if (frame == null)
                {
                    // find frame in scope of ancestor frame content
                    var parent = frames.FirstOrDefault();
                    if (parent != null && parent.Content != null)
                    {
                        var content = parent.Content as FrameworkElement;
                        if (content != null)
                        {
                            frame = content.FindName(name) as ModernFrame;
                        }
                    }
                }
            }

            return frame;
        }
开发者ID:jkmchinese,项目名称:ModernUI,代码行数:57,代码来源:NavigationHelper.cs

示例8: GetBoundMember

        public static object GetBoundMember(FrameworkElement e, string n)
        {
            //Search through the WpfElement's objects
            object result = e.FindName(n);

            if (result == null)
            {
                return OperationFailed.Value;
            }

            return result;

            //If we wanted to add The dynamic Python-type support for adding/removing things to the CLR Classes, we can create a Dict and return the pertinent stuff
            //And also create a SpecialName SetMemberAfter method.
        }
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:15,代码来源:WpfExtentionClass.cs

示例9: FindFrame

        public static FantasyFrame FindFrame(String name, FrameworkElement context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // collect all ancestor frames
            FantasyFrame[] frames = context.Ancestors().OfType<FantasyFrame>().ToArray();
            if (String.IsNullOrEmpty(name) || name.Equals(FrameSelf))
            {
                // find the first frame.
                return frames.FirstOrDefault();
            }
            if (name.Equals(FrameParent))
            {
                // find parent frame
                return frames.Skip(1).FirstOrDefault();
            }
            if (name.Equals(FrameTop))
            {
                // find top-most frame
                return frames.LastOrDefault();
            }

            // find ancestor frame having a name matching the target
            FantasyFrame frame = frames.FirstOrDefault(f => f.Name == name);
            if (frame == null)
            {
                // find frame in context scope
                frame = context.FindName(name) as FantasyFrame;
                if (frame == null)
                {
                    // find frame in scope of ancestor frame content
                    FantasyFrame parent = frames.FirstOrDefault();
                    if (parent != null && parent.Content != null)
                    {
                        FrameworkElement content = parent.Content as FrameworkElement;
                        if (content != null)
                        {
                            frame = content.FindName(name) as FantasyFrame;
                        }
                    }
                }
            }

            return frame;
        }
开发者ID:wjzhangb,项目名称:Fantasy.Repositories,代码行数:48,代码来源:NavigationManager.cs

示例10: GetFirstDataContextInVisualTree

		public static object GetFirstDataContextInVisualTree(FrameworkElement root)
		{
			if (null != root.DataContext)
			{
				return root.DataContext;
			}

			Func<UIElementCollection,object> walkChildren =
				(c) =>
				{
					foreach (FrameworkElement child in c)
					{
						var returnValue = GetFirstDataContextInVisualTree(child);
						if (null != returnValue)
						{
							return returnValue;
						}
					}
					return null;
				};


			object result = null;
			if (root is Panel)
			{
				result = walkChildren(((Panel) root).Children);
			}
			else if( root is Grid )
			{
				result = walkChildren(((Grid) root).Children);
			} else if( root is ContentControl )
			{
				result = GetFirstDataContextInVisualTree((FrameworkElement)((ContentControl)root).Content);
			} else
			{
				var layoutRoot = root.FindName("LayoutRoot") as FrameworkElement;
				if( null != layoutRoot )
				{
					result = GetFirstDataContextInVisualTree(layoutRoot);
				}
			}
			return result;
		}
开发者ID:baldercollaborator,项目名称:Balder,代码行数:43,代码来源:DataContextHelper.cs

示例11: DispatchSubEvent

        public void DispatchSubEvent(FrameworkElement page)
        {
            var filterList = (ListBox)page.FindName("EventFilterList");
            var optionalFiltersList = (ListBox)page.FindName("OptionalEventFilterList");

            _dispatchDelegate = (model, optinalActions) =>
                                    {
                                        var filter = filterList.SelectedValue as Func<Term, bool>;
                                        var optionalFilters = optionalFiltersList.SelectedItems;
                                        Func<Term, bool> where = t =>
                                                           {
                                                               if (!filter(t)) return false;
                                                               foreach (var func in optionalFilters.Cast<ICustomFilter>().Select(o => o.WhereClause).OfType<Func<Term, bool>>())
                                                                   if (!func(t)) return false;
                                                               return true;
                                                           };

                                        var action = default(Action<Term, TimeBox>);
                                        foreach (var act in optinalActions.Cast<ICustomAction>().Select(o => o.Action).OfType<Action<Term, TimeBox>>())
                                            action += act;
                                        TryDispatch(model, where, action);
                                    };
        }
开发者ID:Mrding,项目名称:Ribbon,代码行数:23,代码来源:BatchDispatcherPresenter.cs

示例12: SelectableImage

		/// <summary>
		/// Creates a new SelectableImage
		/// </summary>
		public SelectableImage()
		{
			System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream( "Next2Friends.Swoosher.SelectableImage.xaml" );
			root = this.InitializeFromXaml( new System.IO.StreamReader( s ).ReadToEnd() );
			progress = (ProgressBar)root.FindName( "progress" );
			content = (Canvas)root.FindName( "content" );
			outline = (Rectangle)root.FindName( "outline" );
			border = (Rectangle)root.FindName( "border" );
			selection = (Rectangle)root.FindName( "selection" );
			image = (Image)root.FindName( "image" );
			//webImage = (Image)root.FindName( "webImage" );

			root.Loaded += OnLoaded;

			downloader = new Downloader();
			downloader.DownloadProgressChanged += image_DownloadProgressChanged;
			downloader.DownloadFailed += image_Failed;
			downloader.Completed += image_Completed;
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:22,代码来源:SelectableImage.xaml.cs

示例13: OnEventCreated

        /// 
        /// <summary>
        /// This event fires when event is about to be displayed on the screen,
        /// we attach event handlers to stop/play mediaplayer link here</summary>
        /// 
        void OnEventCreated(
            FrameworkElement                            element,
            TimelineDisplayEvent                        de
            )
        {
            MediaElement                                me;
            TimelineLibrary.Hyperlink                   link;

            me = element.FindName("MediaPlayer") as MediaElement;
            link = element.FindName("StopPlayButton") as TimelineLibrary.Hyperlink;

            if (me != null && link != null)
            {
                link.Tag = me;
                link.Click += new RoutedEventHandler(OnButtonClick);
                me.MediaEnded += new RoutedEventHandler(OnMediaEnded);
                me.Tag = false;
            }
        }
开发者ID:jogibear9988,项目名称:Timeline,代码行数:24,代码来源:MainWindow.xaml.cs

示例14: OnApplyTemplate

        /// <summary>
        /// Builds the visual tree for the control 
        /// when a new template is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            menuContainer = GetTemplateChild(MenuContainer) as FrameworkElement;
            if (menuContainer != null)
            {
                if (RootVisual != null)
                {
                    menuContainer.Width = RootVisual.ActualWidth;
                }

                showMenuAnimation = menuContainer.FindName("storyBoard") as Storyboard;
                if (showMenuAnimation != null)
                {
                    showMenuAnimation.Completed += StoryBoard_Completed;
                }

                for (int i = 0; i < Items.Count; i++)
                {
                    if (Items[i] is TextBlock && ShouldApplyDefaultItemStyle)
                    {
                        TextBlock t = Items[i] as TextBlock;
                        int pos = Items.IndexOf(t);
                        Items.Remove(t);
                        Border border = new Border();
                        border.BorderThickness = new Thickness(0);
                        border.Child = t;
                        border.Margin = t.Margin;
                        t.Margin = new Thickness(0);
                        Items.Insert(pos, border);
                    }
                }
            }

            ChangeVisualState(false);
            isTemplateApplied = true;

            while (afterTemplateApplied.Count > 0)
            {
                var action = afterTemplateApplied.Dequeue();
                action.Invoke();
            }
        }
开发者ID:blueprintmrk,项目名称:Workspaces,代码行数:48,代码来源:ContextMenu.cs

示例15: DispatchAssignment

 public void DispatchAssignment(FrameworkElement page)
 {
     var filterList = (ListBox)page.FindName("AssignmentFilterList");
     _dispatchDelegate = (model, optinalActions) =>
                             {
                                 var filter = filterList.SelectedValue as Func<Term, bool>;
                                 var action = default(Action<Term, TimeBox>);
                                 foreach (var act in optinalActions.Cast<ICustomAction>().Select(o => o.Action).OfType<Action<Term, TimeBox>>())
                                     action += act;
                                 TryDispatch(model, filter, action);
                             };
 }
开发者ID:Mrding,项目名称:Ribbon,代码行数:12,代码来源:BatchDispatcherPresenter.cs


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