示例#1
0
        /// <summary>Create a <see cref="Xaml.Controls.ContentPresenter"/></summary>
        /// <remarks>Remark: ContentPresenter().Bind() binds to <see cref="Xaml.Controls.ContentPresenter.ContentProperty"/></remarks>
        public static ContentPresenter ContentPresenter()
        {
            var ui     = new Xaml.Controls.ContentPresenter();
            var markup = CSharpMarkup.WinUI.ContentPresenter.StartChain(ui);

            // In WinUI we use a workaround to simulate template bindings, so we have to explicitly create equivalent bindings
            // for the bindings that ContentPresenter creates by default.
            if (DependencyObjectExtensions.TemplatedParent is not null)
            {
                markup.Content().BindTemplate("Content")
                .ContentTemplate().BindTemplate("ContentTemplate")
                .ContentTemplateSelector().BindTemplate("ContentTemplateSelector");
            }

            return(markup);
        }
示例#2
0
        // Specify parameter properties to include them in derived types

#if HAS_UNO
        /// <summary>Create a <see cref="Xaml.Controls.ContentPresenter"/></summary>
        /// <remarks>Remark: ContentPresenter().Bind() binds to <see cref="Xaml.Controls.ContentPresenter.ContentProperty"/></remarks>
        public static ContentPresenter ContentPresenter()
        {
            var ui     = new Xaml.Controls.ContentPresenter();
            var markup = CSharpMarkup.WinUI.ContentPresenter.StartChain(ui);

            // In UNO the implicit binding to Content* properties that should happen when the ContentPresenter is in a ControlTemplate
            // (see https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.controls.contentpresenter?view=winui-3.0#remarks)
            // does not happen; see UNO issues https://github.com/unoplatform/uno/issues/857 and https://github.com/unoplatform/uno/issues/6452
            // Below is a workaround to do this implicit binding if the ContentPresenter is in a ControlTemplate.
            if (buildingControlTemplate)
            {
                markup.Content().BindTemplate("Content")
                .ContentTemplate().BindTemplate("ContentTemplate")
                .ContentTemplateSelector().BindTemplate("ContentTemplateSelector");
            }

            return(markup);
        }