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


C# Xaml.FrameworkElement类代码示例

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


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

示例1: BindWindow

        /// <summary>
        /// Binds to specific events of the provided CoreWindow
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="nativeWindow"/> is null.</exception>
        /// <exception cref="ArgumentException">Is thrown when <paramref name="nativeWindow"/> is not a <see cref="CoreWindow"/> and not an <see cref="UIElement"/></exception>
        protected override void BindWindow(object nativeWindow)
        {
            if (nativeWindow == null) throw new ArgumentNullException("nativeWindow");
            var window = nativeWindow as CoreWindow;
            if (window != null)
            {
                windowSize = new Size2F((float)window.Bounds.Width, (float)window.Bounds.Height);
                var position = window.PointerPosition;
                pointerPosition = new Vector2((float)position.X/windowSize.Width, (float)position.Y / windowSize.Height);

                window.PointerPressed += HandleWindowPointerEvent;
                window.PointerReleased += HandleWindowPointerEvent;
                window.PointerWheelChanged += HandleWindowPointerEvent;
                window.PointerMoved += HandleWindowPointerEvent;
                window.SizeChanged += window_SizeChanged;
                return;
            }

            uiElement = nativeWindow as FrameworkElement;
            if (uiElement != null)
            {
                windowSize = new Size2F((float)uiElement.ActualWidth, (float)uiElement.ActualHeight);
                uiElement.Loaded += HandleLoadedEvent;
                uiElement.SizeChanged += HandleSizeChangedEvent;
                uiElement.PointerPressed += HandleUIElementPointerEvent;
                uiElement.PointerReleased += HandleUIElementPointerEvent;
                uiElement.PointerWheelChanged += HandleUIElementPointerEvent;
                uiElement.PointerMoved += HandleUIElementPointerEvent;
                uiElement.PointerEntered += HandleUIElementPointerEvent;
                return;
            }

            throw new ArgumentException("Should be an instance of either CoreWindow or UIElement", "nativeWindow");
        }
开发者ID:chantsunman,项目名称:Toolkit,代码行数:40,代码来源:MousePlatformWinRt.cs

示例2: FindNearestStatefulControl

        public static Control FindNearestStatefulControl(FrameworkElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            // Try to find an element which is the immediate child of a UserControl, ControlTemplate or other such "boundary" element
            FrameworkElement parent = element.Parent as FrameworkElement;

            // bubble up looking for a place to stop
            while (!VisualStateUtilities.HasVisualStateGroupsDefined(element) && VisualStateUtilities.ShouldContinueTreeWalk(parent))
            {
                element = parent;
                parent = parent.Parent as FrameworkElement;
            }

            if (VisualStateUtilities.HasVisualStateGroupsDefined(element))
            {
                // Once we've found such an element, use the VisualTreeHelper to get it's parent. For most elements the two are the 
                // same, but for children of a ControlElement this will give the control that contains the template.
                Control templatedParent = VisualTreeHelper.GetParent(element) as Control;

                if (templatedParent != null)
                {
                    return templatedParent;
                }
                else
                {
                    return element as Control;
                }
            }

            return null;
        }
开发者ID:blinds52,项目名称:XamlBehaviors,代码行数:35,代码来源:VisualStateUtilities.cs

示例3: IsInPopup

        /// <summary>
        /// Returns true if the element is contained in a popup. 
        /// </summary>
        public static bool IsInPopup(FrameworkElement element)
        {
            if (element is Popup)
                return true;

            return GetParentPopup(element) != null; 
        }
开发者ID:RareNCool,项目名称:MyToolkit,代码行数:10,代码来源:PopupHelper.cs

示例4: Render

        internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Line line)
        {
            var rect = line.GetBoundingRect(rootElement).ToSharpDX();
            var stroke = await line.Stroke.ToSharpDX(renderTarget, rect);

            if (stroke == null ||
                line.StrokeThickness <= 0)
            {
                return;
            }

            var layer = line.CreateAndPushLayerIfNecessary(renderTarget, rootElement);

            renderTarget.DrawLine(
                new Vector2(
                    rect.Left + (float)line.X1,
                    rect.Top + (float)line.Y1),
                new Vector2(
                    rect.Left + (float)line.X2,
                    rect.Top + (float)line.Y2),
                    stroke,
                    (float)line.StrokeThickness,
                    line.GetStrokeStyle(compositionEngine.D2DFactory));

            if (layer != null)
            {
                renderTarget.PopLayer();
                layer.Dispose();
            }
        }
开发者ID:cstehreem,项目名称:WinRTXamlToolkit,代码行数:30,代码来源:LineRenderer.cs

示例5: IsItemVisible

        public static bool IsItemVisible(this FrameworkElement container, FrameworkElement element)
        {
            var elementBounds = element.TransformToVisual(container).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight));
            var containerBounds = new Rect(0, 0, container.ActualWidth, container.ActualHeight);

            return (elementBounds.Top < containerBounds.Bottom && elementBounds.Bottom > containerBounds.Top);
        }
开发者ID:JustinXinLiu,项目名称:Parallax,代码行数:7,代码来源:Extensions.cs

示例6: GoToVisualStateAsync

        /// <summary>
        /// Goes to specified visual state, waiting for the transition to complete.
        /// </summary>
        /// <param name="control">
        /// Control to transition.
        /// </param>
        /// <param name="visualStatesHost">
        /// FrameworkElement that defines the visual states
        /// (usually the root of the control's template).
        /// </param>
        /// <param name="stateGroupName">
        /// Name of the state group
        /// (speeds up the search for the state transition storyboard).
        /// </param>
        /// <param name="stateName">
        /// State to transition to.
        /// </param>
        /// <returns>
        /// Awaitable task that completes when the transition storyboard completes.
        /// </returns>
        /// <remarks>
        /// If a state transition storyboard is not found - the task
        /// completes immediately.
        /// </remarks>
        public static async Task GoToVisualStateAsync(
            this Control control,
            FrameworkElement visualStatesHost, 
            string stateGroupName,
            string stateName)
        {
            var tcs = new TaskCompletionSource<Storyboard>();

            Storyboard storyboard =
                GetStoryboardForVisualState(visualStatesHost, stateGroupName, stateName);

            if (storyboard != null)
            {
                EventHandler<object> eh = null;

                eh = (s, e) =>
                {
                    storyboard.Completed -= eh;
                    tcs.SetResult(storyboard);
                };

                storyboard.Completed += eh;
            }

            VisualStateManager.GoToState(control, stateName, true);

            if (storyboard == null)
            {
                return;
            }

            await tcs.Task;
        }
开发者ID:chao-zhou,项目名称:PomodoroTimer,代码行数:57,代码来源:ControlExtensions.cs

示例7: RevertRequestedTheme

 private void RevertRequestedTheme(FrameworkElement fe)
 {
     if (fe.RequestedTheme == ElementTheme.Default)
     {
         //The FrameworkElement doesn't have a RequestedTheme set, 
         //so we will need to ask to the Application what theme is using.
         if (Application.Current.RequestedTheme == ApplicationTheme.Dark)
         {
             fe.RequestedTheme = ElementTheme.Light;
         }
         else
         {
             fe.RequestedTheme = ElementTheme.Dark; 
         }
     }
     else if (fe.RequestedTheme == ElementTheme.Dark)
     {
         fe.RequestedTheme = ElementTheme.Light;
     }
     else
     {
         fe.RequestedTheme = ElementTheme.Dark;
     }
     CurrentThemeTxtBlock.Text = "Current theme is " + fe.RequestedTheme.ToString() + ".";
 }
开发者ID:mbin,项目名称:Win81App,代码行数:25,代码来源:Scenario4.xaml.cs

示例8: GoToStateInternal

        private bool GoToStateInternal(FrameworkElement stateGroupsRoot, string stateName, bool useTransitions)
        {
            VisualStateGroup group;
            VisualState state;

            return (TryGetState(stateGroupsRoot, stateName, out group, out state) && this.GoToStateCore(null, stateGroupsRoot, stateName, group, state, useTransitions));
        }
开发者ID:smndtrl,项目名称:Signal-UWP,代码行数:7,代码来源:ExtendedVisualStateManager.cs

示例9: GetSamples

        /// <summary>Construct Get Image Samples sample control</summary>
        public GetSamples()
        {
            InitializeComponent();
			_graphicsOverlay = MyMapView.GraphicsOverlays.First();
			_mapTip = MyMapView.Overlays.Items.First() as FrameworkElement;
            MyMapView.LayerLoaded += MyMapView_LayerLoaded;
        }
开发者ID:MagicWang,项目名称:arcgis-runtime-samples-dotnet,代码行数:8,代码来源:GetSamples.xaml.cs

示例10: IntersectsWith

        /// <summary>
        /// Decides whether the specified framework elements intersect within a canvas.
        /// </summary>
        /// <param name="first">The first framework element.</param>
        /// <param name="second">The second framework element.</param>
        /// <returns>True if the elements intersect. False otherwise.</returns>
        public static bool IntersectsWith(this FrameworkElement first, FrameworkElement second)
        {
            Rect p1 = first.Position();
            Rect p2 = second.Position();

            return (p1.Y + p1.Height < p2.Y) || (p1.Y > p2.Y + p2.Height) || (p1.X + p1.Width < p2.X) || (p1.X > p2.X + p2.Width);
        }
开发者ID:L-SEG,项目名称:Vitruvius,代码行数:13,代码来源:UIExtensions.cs

示例11: ConsoleGainFocus

 private void ConsoleGainFocus(FrameworkElement grid)
 {
     ShowBackgroundImage(((Console)grid.DataContext).BackgroundLink);
     ConsoleFocus.Stop();
     Storyboard.SetTarget(ConsoleFocus, grid);
     ConsoleFocus.Begin();
 }
开发者ID:brpeanut,项目名称:emu-pi2,代码行数:7,代码来源:MainPage.xaml.cs

示例12: GetDefaultGenerators

        /// <summary>Creates the default UI element generators.</summary>
        /// <param name="view">The view.</param>
        /// <returns>The generators.</returns>
        public static Dictionary<string, IControlGenerator> GetDefaultGenerators(FrameworkElement view)
        {
            var list = new Dictionary<string, IControlGenerator>();

            list.Add("p", new ParagraphGenerator());
            list.Add("div", new ParagraphGenerator());
            list.Add("blockquote", new ParagraphGenerator());
            list.Add("h1", new ParagraphGenerator { FontSize = 1.6 });
            list.Add("h2", new ParagraphGenerator { FontSize = 1.4 });
            list.Add("h3", new ParagraphGenerator { FontSize = 1.2 });

            list.Add("html", new HtmlGenerator());
            list.Add("strong", new StrongGenerator());
            list.Add("b", list["strong"]);
            list.Add("text", new TextGenerator());
            list.Add("em", new EmGenerator());
            list.Add("i", list["em"]);
            list.Add("a", new LinkGenerator());
            list.Add("img", new CacheImageGenerator());
            //list.Add("img", new ImageGenerator());
            list.Add("ul", new UlGenerator());
            list.Add("script", new EmptyGenerator());

            return list;
        }
开发者ID:startewho,项目名称:CnBetaUWA,代码行数:28,代码来源:HtmlControlHelper.cs

示例13: Render

        internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Line line)
        {
            var rect = line.GetBoundingRect(rootElement).ToSharpDX();
            //var fill = line.Fill.ToSharpDX(renderTarget, rect);
            var stroke = await line.Stroke.ToSharpDX(renderTarget, rect);

            if (stroke == null ||
                line.StrokeThickness <= 0)
            {
                return;
            }

            //var layer = new Layer(renderTarget);
            //var layerParameters = new LayerParameters();
            //layerParameters.ContentBounds = rect;
            //renderTarget.PushLayer(ref layerParameters, layer);

            renderTarget.DrawLine(
                new DrawingPointF(
                    rect.Left + (float)line.X1,
                    rect.Top + (float)line.Y1),
                new DrawingPointF(
                    rect.Left + (float)line.X2,
                    rect.Top + (float)line.Y2),
                    stroke,
                    (float)line.StrokeThickness,
                    line.GetStrokeStyle(compositionEngine.D2DFactory));

            //renderTarget.PopLayer();
        }
开发者ID:prabaprakash,项目名称:Visual-Studio-2013,代码行数:30,代码来源:LineRenderer.cs

示例14: UserControl_DataContextChanged

        private void UserControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            Graph.ClearSeries();

            var item = DataContext as ChartSong;
            if (item == null) return;

            var color = Colors.White;

            switch (item.ChangeDirection)
            {
                case ChartSong.Direction.Up:
                    color = Colors.Green;
                    break;
                case ChartSong.Direction.Down:
                    color = Colors.Red;
                    break;
            }

            ChangePercentBlock.Foreground = new SolidColorBrush(color);

            var data = item.Signals.Select((p, i) => new Point(i, p)).ToList();

            var serie = new Serie("Signals") {ShiftSize = 100};
            serie.SetData(data);

            Graph.AutoRedraw = true;
            Graph.AddSerie(serie);
        }
开发者ID:jayharry28,项目名称:Audiotica,代码行数:29,代码来源:ChartSongViewer.xaml.cs

示例15: Render

        //Do not use the below extension as it is slower than the one that follows
        //public static async Task Render(this WriteableBitmap wb, FrameworkElement fe)
        //{
        //    var ms = await RenderToPngStream(fe);

        //    using (var msrandom = new MemoryRandomAccessStream(ms))
        //    {
        //        await wb.SetSourceAsync(msrandom);
        //    }
        //}

        public static async Task<WriteableBitmap> Render(FrameworkElement fe)
        {
            using (var engine = new CompositionEngine())
            {
                return await engine.RenderToWriteableBitmap(fe);
            }
        }
开发者ID:prabaprakash,项目名称:Visual-Studio-2013,代码行数:18,代码来源:WriteableBitmapRenderExtensions.cs


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