CompositionObject 클래스

정의

시각적 트리 구조의 노드를 나타내는 컴퍼지션 API의 기본 클래스입니다.

컴퍼지션 개체는 컴퍼지션 API의 다른 모든 기능이 사용하고 빌드하는 시각적 트리 구조입니다. API를 사용하면 개발자가 각각 시각적 트리의 단일 노드를 나타내는 하나 이상의 시각적 개체를 정의하고 만들 수 있습니다.

[WebHostHidden]
public ref class CompositionObject : IClosable
public ref class CompositionObject : IClosable
public ref class CompositionObject : IClosable, IAnimationObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[WebHostHidden]
class CompositionObject : IClosable
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 131072)]
class CompositionObject : IClosable
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 131072)]
class CompositionObject : IClosable, IAnimationObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class CompositionObject : System.IDisposable
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 131072)]
public class CompositionObject : System.IDisposable
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 131072)]
public class CompositionObject : System.IDisposable, IAnimationObject
Public Class CompositionObject
Implements IDisposable
Public Class CompositionObject
Implements IAnimationObject, IDisposable
상속
Object Platform::Object IInspectable CompositionObject
파생
특성
구현

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

이 샘플에서는 XAML, WWA 또는 DirectX를 사용하지 않고 컴퍼지션 API를 사용하여 자체 포함 앱을 만드는 방법을 보여줍니다. 샘플은 새 Compositor를 초기화한 다음 SpriteVisual 개체 두 개를 사용하여 장면 그래프를 만듭니다.

using System;
using System.Numerics;

using Windows.ApplicationModel.Core;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Core;

namespace HelloCompositionCs
{
    public sealed class HelloComposition : IFrameworkView
    {
        //------------------------------------------------------------------------------
        //
        // HelloComposition.Initialize
        //
        // This method is called during startup to associate the IFrameworkView with the
        // CoreApplicationView.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Initialize(CoreApplicationView view)
        {
            _view = view;
        }


        //------------------------------------------------------------------------------
        //
        // HelloComposition.SetWindow
        //
        // This method is called when the CoreApplication has created a new CoreWindow,
        // allowing the application to configure the window and start producing content
        // to display.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.SetWindow(CoreWindow window)
        {
            _window = window;
            InitNewComposition();
        }


        //------------------------------------------------------------------------------
        //
        // HelloComposition.Load
        //
        // This method is called when a specific page is being loaded in the
        // application.  It is not used for this application.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Load(string unused)
        {

        }


        //------------------------------------------------------------------------------
        //
        // HelloComposition.Run
        //
        // This method is called by CoreApplication.Run to actually run the
        // dispatcher's message pump.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Run()
        {
            _window.Activate();
            _window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
        }


        //------------------------------------------------------------------------------
        //
        // HelloComposition.Uninitialize
        //
        // This method is called during shutdown to disconnect the CoreApplicationView,
        // and CoreWindow from the IFrameworkView.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Uninitialize()
        {
            _window = null;
            _view = null;
        }


        //------------------------------------------------------------------------------
        //
        // HelloComposition.InitNewComposition
        //
        // This method is called by SetWindow, where we initialize Composition after
        // the CoreWindow has been created.
        //
        //------------------------------------------------------------------------------

        void InitNewComposition()
        {
            //
            // Set up Windows.UI.Composition Compositor, root ContainerVisual, and associate with
            // the CoreWindow.
            //

            _compositor = new Compositor();

            _root = _compositor.CreateContainerVisual();
            _view.CompositionRootVisual = _root;


            //
            // Create a simple scene.
            //

            var child1 = _compositor.CreateSpriteVisual();
            child1.Offset = new Vector2(50.0f, 50.0f);
            child1.Size = new Vector2(200, 200);
            child1.Brush = _compositor.CreateColorBrush(Color.FromArgb(0xFF, 0x00, 0xCC, 0x00));

            _root.Children.InsertAtTop(child1);

            var child2 = _compositor.CreateSpriteVisual();
            child2.Offset = new Vector2(50.0f, 50.0f);
            child2.Size = new Vector2(200, 200);
            child2.Brush = _compositor.CreateColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0xCC));

            child1.Children.InsertAtTop(child2);

        }


        // CoreWindow / CoreApplicationView
        private CoreWindow _window;
        private CoreApplicationView _view;

        // Windows.UI.Composition
        private Compositor _compositor;
        private ContainerVisual _root;
    }


    public sealed class HelloCompositionFactory : IFrameworkViewSource
    {
        //------------------------------------------------------------------------------
        //
        // HelloCompositionFactory.CreateView
        //
        // This method is called by CoreApplication to provide a new IFrameworkView for
        // a CoreWindow that is being created.
        //
        //------------------------------------------------------------------------------

        IFrameworkView IFrameworkViewSource.CreateView()
        {
            return new HelloComposition();
        }


        //------------------------------------------------------------------------------
        //
        // main
        //
        //------------------------------------------------------------------------------

        static int Main(string[] args)
        {
            CoreApplication.Run(new HelloCompositionFactory());

            return 0;
        }
    }

} // namespace HelloCompositionCs

이 샘플에서는 XAML, WWA 또는 DirectX를 사용하지 않고 불투명도를 변경하기 위해 간단한 시각적 개체 트리를 구성하고 안내하는 방법을 보여 줍니다. 이 샘플은 이전 샘플을 기반으로 자식 시각적 개체를 만들고, 추가하고, 속성을 변경하는 방법을 보여 줍니다.

이 시나리오에서는 Visuals의 시각적 트리 계층 구조가 빌드됩니다. Compositor가 만들어지면 관리할 수 있는 개체를 만드는 데 사용됩니다.

//  Copyright (c) Microsoft Corporation. All rights reserved.

using System;
using System.Numerics;

using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Core;

namespace VisualTreeCs
{
    public sealed class VisualTree : IFrameworkView
    {
        //------------------------------------------------------------------------------
        //
        // VisualTree.Initialize
        //
        // This method is called during startup to associate the IFrameworkView with the
        // CoreApplicationView.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Initialize(CoreApplicationView view)
        {
            _view = view;
            _random = new Random();
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.SetWindow
        //
        // This method is called when the CoreApplication has created a new CoreWindow,
        // allowing the application to configure the window and start producing content
        // to display.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.SetWindow(CoreWindow window)
        {
            _window = window;
            InitNewComposition();
            _window.PointerPressed += OnPointerPressed;
            _window.PointerMoved += OnPointerMoved;
            _window.PointerReleased += OnPointerReleased;
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.OnPointerPressed
        //
        // This method is called when the user touches the screen, taps it with a stylus
        // or clicks the mouse.
        //
        //------------------------------------------------------------------------------

        void OnPointerPressed(CoreWindow window, PointerEventArgs args)
        {
            Point position = args.CurrentPoint.Position;

            //
            // Walk our list of visuals to determine who, if anybody, was selected
            //
            foreach (var child in _root.Children)
            {
                //
                // Did we hit this child?
                //
                Vector2 offset = child.Offset;
                Vector2 size = child.Size;

                if ((position.X >= offset.X) &&
                    (position.X < offset.X + size.X) &&
                    (position.Y >= offset.Y) &&
                    (position.Y < offset.Y + size.Y))
                {
                    //
                    // This child was hit. Since the children are stored back to front,
                    // the last one hit is the front-most one so it wins
                    //
                    _currentVisual = child;
                    _offsetBias = new Vector2((float)(offset.X - position.X),
                                              (float)(offset.Y - position.Y));
                }
            }

            //
            // If a visual was hit, bring it to the front of the Z order
            //
            if (_currentVisual != null)
            {
                ContainerVisual parent = _currentVisual.Parent as ContainerVisual;
                parent.Children.Remove(_currentVisual);
                parent.Children.InsertAtTop(_currentVisual);
            }
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.OnPointerMoved
        //
        // This method is called when the user moves their finger, stylus or mouse with
        // a button pressed over the screen.
        //
        //------------------------------------------------------------------------------

        void OnPointerMoved(CoreWindow window, PointerEventArgs args)
        {
            //
            // If a visual is selected, drag it with the pointer position and
            // make it opaque while we drag it
            //
            if (_currentVisual != null)
            {
                Point position = args.CurrentPoint.Position;
                _currentVisual.Opacity = 1.0f;
                _currentVisual.Offset = new Vector2((float)(position.X + _offsetBias.X),
                                                    (float)(position.Y + _offsetBias.Y));
            }
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.OnPointerReleased
        //
        // This method is called when the user lifts their finger or stylus from the
        // screen, or lifts the mouse button.
        //
        //------------------------------------------------------------------------------

        void OnPointerReleased(CoreWindow window, PointerEventArgs args)
        {
            //
            // If a visual was selected, make it transparent again when it is
            // released
            //
            if (_currentVisual != null)
            {
                _currentVisual.Opacity = 0.8f;
                _currentVisual = null;
            }
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.Load
        //
        // This method is called when a specific page is being loaded in the
        // application.  It is not used for this application.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Load(string unused)
        {

        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.Run
        //
        // This method is called by CoreApplication.Run to actually run the
        // dispatcher's message pump.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Run()
        {
            _window.Activate();
            _window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.Uninitialize
        //
        // This method is called during shutdown to disconnect the CoreApplicationView,
        // and CoreWindow from the IFrameworkView.
        //
        //------------------------------------------------------------------------------

        void IFrameworkView.Uninitialize()
        {
            _window = null;
            _view = null;
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.InitNewComposition
        //
        // This method is called by SetWindow, where we initialize Composition after
        // the CoreWindow has been created.
        //
        //------------------------------------------------------------------------------

        void InitNewComposition()
        {
            //
            // Set up Windows.UI.Composition Compositor, root ContainerVisual, and associate with
            // the CoreWindow.
            //

            _compositor = new Compositor();

            _root = _compositor.CreateContainerVisual();
            _view.CompositionRootVisual = _root;

            //
            // Create a few visuals for our window
            //
            for (int index = 0; index < 20; index++)
            {
                _root.Children.InsertAtTop(CreateChildElement());
            }
        }

        //------------------------------------------------------------------------------
        //
        // VisualTree.CreateChildElement
        //
        // Creates a small sub-tree to represent a visible element in our application.
        //
        //------------------------------------------------------------------------------

        Visual CreateChildElement()
        {
            //
            // Each element consists of two visuals, which produce the appearance
            // of a framed rectangle
            //
            var visual = _compositor.CreateSpriteVisual();

            //
            // Position this visual randomly within our window
            //
            visual.Offset = new Vector2((float)(_random.NextDouble() * 400), (float)(_random.NextDouble() * 400));

            //
            // The outer rectangle is always white
            //
            visual.Brush = _compositor.CreateColorBrush( Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF) );
            visual.Size = new Vector2(100.0f, 100.0f);

            //
            // The inner rectangle is inset from the outer by three pixels all around
            //
            var child = _compositor.CreateSpriteVisual();
            visual.Children.InsertAtTop(child);
            child.Offset = new Vector2(3.0f, 3.0f);
            child.Size = new Vector2(94.0f, 94.0f);

            //
            // Pick a random color for every rectangle
            //
            byte red = (byte)(0xFF * (0.2f + (_random.NextDouble() / 0.8f)));
            byte green = (byte)(0xFF * (0.2f + (_random.NextDouble() / 0.8f)));
            byte blue = (byte)(0xFF * (0.2f + (_random.NextDouble() / 0.8f)));
            child.Brush = _compositor.CreateColorBrush( Color.FromArgb(0xFF, red, green, blue) );

            //
            // Make the subtree root visual partially transparent. This will cause each visual in the subtree
            // to render partially transparent, since a visual's opacity is multiplied with its parent's
            // opacity
            //
            visual.Opacity = 0.8f;

            return visual;
        }

        // CoreWindow / CoreApplicationView
        private CoreWindow _window;
        private CoreApplicationView _view;

        // Windows.UI.Composition
        private Compositor _compositor;
        private ContainerVisual _root;
        private Visual _currentVisual;
        private Vector2 _offsetBias;

        // Helpers
        private Random _random;
    }


    public sealed class VisualTreeFactory : IFrameworkViewSource
    {
        //------------------------------------------------------------------------------
        //
        // VisualTreeFactory.CreateView
        //
        // This method is called by CoreApplication to provide a new IFrameworkView for
        // a CoreWindow that is being created.
        //
        //------------------------------------------------------------------------------

        IFrameworkView IFrameworkViewSource.CreateView()
        {
            return new VisualTree();
        }

        //------------------------------------------------------------------------------
        //
        // main
        //
        //------------------------------------------------------------------------------

        static int Main(string[] args)
        {
            CoreApplication.Run(new VisualTreeFactory());

            return 0;
        }
    }

} // namespace VisualTreeCs

설명

Compositor 개체를 사용하여 개체를 만듭니다. 컴퍼지션 개체는 컨테이너만 가능하거나 콘텐츠를 보유할 수 있습니다. API를 사용하면 계층 구조에 있는 특정 작업에 대해 명확한 시각적 개체 집합을 제공하여 쉽게 사용할 수 있습니다.

  • Visual - 기준 개체, 대부분의 속성은 여기에 있으며 다른 시각적 개체에 의해 상속됩니다.

  • ContainerVisual - Visual에서 파생되며 자식을 만들 수 있는 기능을 추가합니다.

  • SpriteVisualContainerVisual에서 파생되며 이미지, 효과 및 스왑 체인 형식의 콘텐츠를 포함합니다.

  • Compositor – 애플리케이션과 시스템 작성기 프로세스 간의 관계를 관리합니다. 애니메이션은 애니메이션이 애니메이션 가능한 컴퍼지션 개체의 속성(예: Visual)을 업데이트합니다. 애니메이션에는 두 가지 유형이 있습니다.

  • KeyFrameAnimation: 둘 이상의 키 프레임이 있는 시간 기반 애니메이션입니다. 이러한 프레임은 마커이므로 개발자는 지정된 시간에 애니메이션 값이 무엇인지 정의할 수 있습니다. 애니메이션이 키 프레임 간의 값을 보간(혼합)하는 방법을 지정하여 애니메이션을 미세 조정할 수도 있습니다. KeyFrameAnimation 에는 각각 다른 유형의 키 프레임 값을 지원하는 많은 서브클래스가 있습니다.

  • ExpressionAnimation: 수학적 식을 사용하여 애니메이션 값을 각 프레임에 계산하는 방법을 지정하는 애니메이션입니다. 식은 컴퍼지션 개체의 속성을 참조할 수 있습니다. ExpressionAnimations는 시간 기반이 아니며 각 프레임(필요한 경우)으로 처리됩니다.

기본 시각적 개체

기본 시각적 개체(예: SpriteVisual)는 화면의 시각적 콘텐츠와 해당 콘텐츠에 적용될 렌더링 옵션을 설명합니다.

효과

이미지 또는 시각적 개체 트리와 같은 원본 콘텐츠에 동적 픽셀 변경을 발생시키기 위해 효과를 시각적 트리에 연결할 수 있습니다.

효과는 소멸, 흐리게와 같은 더 복잡한 작업 또는 교차 페이드와 같은 매우 복잡한 A B 혼합 작업과 같은 간단한 작업일 수 있습니다.

효과를 만들고 사용하는 방법에 대한 자세한 내용은 CompositionEffectBrush 의 설명 섹션을 참조하세요.

버전 기록

Windows 버전 SDK 버전 추가된 값
1607 14393 의견
1607 14393 ImplicitAnimations
1607 14393 StartAnimationGroup
1607 14393 StopAnimationGroup
1709 16299 DispatcherQueue
1803 17134 TryGetAnimationController
1809 17763 PopulatePropertyInfo
1809 17763 StartAnimationGroupWithIAnimationObject
1809 17763 StartAnimationWithIAnimationObject

속성

Comment

CompositionObject와 연결할 문자열입니다.

Compositor

CompositionObject를 만드는 데 사용되는 Compositor입니다.

Dispatcher

CompositionObject의 디스패처입니다.

DispatcherQueue

CompostionObject에 대한 DispatcherQueue 를 가져옵니다.

ImplicitAnimations

이 개체에 연결된 암시적 애니메이션의 컬렉션입니다.

Properties

CompositionObject와 연결된 속성의 컬렉션입니다.

메서드

Close()

CompositionObject를 닫고 시스템 리소스를 해제합니다.

ConnectAnimation(String, CompositionAnimation)

연결 및 애니메이션.

DisconnectAnimation(String)

애니메이션의 연결을 끊습니다.

Dispose()

관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.

PopulatePropertyInfo(String, AnimationPropertyInfo)

애니메이션 효과를 주는 속성을 정의합니다.

StartAnimation(String, CompositionAnimation)

개체의 지정된 속성에 애니메이션을 연결하고 애니메이션을 시작합니다.

StartAnimation(String, CompositionAnimation, AnimationController)

개체의 지정된 속성에 애니메이션을 연결하고 애니메이션을 시작합니다.

StartAnimationGroup(ICompositionAnimationBase)

애니메이션 그룹을 시작합니다.

CompositionObject의 StartAnimationGroup 메서드를 사용하면 CompositionAnimationGroup을 시작할 수 있습니다. 그룹의 모든 애니메이션은 개체에서 동시에 시작됩니다.

StartAnimationGroupWithIAnimationObject(IAnimationObject, ICompositionAnimationBase)

지정된 대상에서 애니메이션 그룹을 시작합니다.

StartAnimationWithIAnimationObject(IAnimationObject, String, CompositionAnimation)

애니메이션을 대상 개체의 지정된 속성과 연결하고 애니메이션을 시작합니다.

StopAnimation(String)

지정된 속성에서 애니메이션의 연결을 끊고 애니메이션을 중지합니다.

StopAnimationGroup(ICompositionAnimationBase)

애니메이션 그룹을 중지합니다.

TryGetAnimationController(String)

지정된 속성에서 실행되는 애니메이션에 대한 AnimationController를 반환합니다.

적용 대상

추가 정보