I have a control template for the teleic tile and I am overriding like the following:
& lt; ControlTemplate TargetType = "{x: Type ctrl: tile}" & gt; & Lt; Border & gt; & Lt; Local: UserControl & gt; & Lt; ContentPresenter Content = "{TemplateBinding Content}" Content Template = "{TemplateBinding Content Template}" /> & Lt; / Local: UserControl & gt; & Lt; / Border & gt; & Lt; / ControlTemplate & gt; My user control looks like this:
& lt; DocPanel & gt; & Lt ;! - Some content - & gt; & Lt; ContentPresenter / & gt; & Lt; / DockPanel & gt; ControlTemplate does not display the contents of UserControl
If I change my control template to:
& lt; ControlTemplate TargetType = "{x: type ctrl: tile}" & gt; & Lt; Border & gt; & Lt; StackPanel & gt; & Lt; Local: UserControl / & gt; & Lt; ContentPresenter Content = "{TemplateBinding Content}" Content Template = "{TemplateBinding Content Template}" /> & Lt; / StackPanel & gt; & Lt; / Border & gt; & Lt; / ControlTemplate & gt; This content will be found and keep it properly. It looks as if contrastsetal content is not nested inside my user root. Is there anything I can do wrong?
Note that these controltemplate items are visible in item renderer.
You are treating UserControl as if it is a basic ContentControl is (such as a button ) which is slightly different. What exactly is this when using the button as an example, when you use a < Code> TextBlock in a button element which in fact is the TextBlock as the content of the button property. The way it is sung, it happens through the button of ControlTemplate , to inject ContentPresenter to content. . The visual tree ends in such a way: & lt; Button & gt; -Initial Template & lt; Border & gt; & Lt; ContentPresenter & gt; -start content & lt; TextBlock & gt; So far it is a basic model that follows your code. The problem is that you are still using UserControl (still generated ContentControl ), which instead of using ControlTemplate Often defined XAML + code-behind model, where XAML defines content of UserControl . (Switching these models and template to UserControl or create a button derived class with XML or XML code-back but not normal) If you want to define both of your form as normal as your UserControl and still be able to inject other content, you can use another DependencyProperty Which can mirror the establishment of the material Set the content to it This approach is used with HeaderedContentControl derivatives (i.e. expander ), which basically has 2 content properties, content And header . New property usage will look like this: & lt; Border & gt; & Lt; Local: UserControl & gt; & Lt; Local: UserControl.OtherContent & gt; & Lt; ContentPresenter Content = "{TemplateBinding Content}" Content Template = "{TemplateBinding Content Template}" /> & Lt; / Local: UserControl.OtherContent & gt; & Lt; / Local: UserControl & gt; & Lt; / Border & gt; Within the XAML of and then UserControl , you need to explicitly set up the ContentPresenter binding (you can only download them for free You can get templates for ContentControls ): & lt; DocPanel & gt; & Lt ;! - Some content - & gt; & Lt; ContentPresenter Content = "{Binding Path = Other Content, Relative Soros = {ResaleSource Mode = Search Installers, Exterior Tire = User Control}}" / & gt; & Lt; / DockPanel & gt; If you want ContentTemplate , ContentTemplateSelector , or ContentStringFormat , then you have to add properties and those people Binding for
No comments:
Post a Comment