What is needed to have a designable Templated Custom Control.

잠김 What is needed to have a designable Templated Custom Control.

  • 2012년 3월 31일 토요일 오후 1:25
     
      코드 있음

    I try to create a custom control with 3 designable areas. After 2 weeks of unsucessfull digging around with reflector i startet a little test...

    I created a custom control derived from Control with exact one property called "Content" as default property, created a Template, a PlacementAdapter and a ParentAdapter...

    It works well, i can drag content in and out of the control in VS designer. Then i added a Border to my Template like this:

        <Style TargetType="{x:Type local:MyContentControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:MyContentControl}">
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="20"/>
                                </Grid.ColumnDefinitions>
                                <Border
                                    BorderBrush="Red"
                                    BorderThickness="1"
    				Grid.Column="1"
                                    />
                                <ContentPresenter
                                    />
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    From this time on it is not posible to select "MyControl" by a click in designer or to drag content into the Control.

    After reading msdn's Extensibility Documentation i have no clue why this happens or how to enable selection and draging for a such template.

    Emmo

    • 편집됨 mo2000 2012년 3월 31일 토요일 오후 1:26
    •  

모든 응답

  • 2012년 4월 1일 일요일 오후 11:31
     
     답변됨

    And the Answer is:

    Its imposible!

    Deep in the MS.Internal Drag & Drop- and Selection-code are "some" checks for ContentControl and HeaderedItemsControl. that makes all attempts to have a Control with more than 2 "Designable" areas a joke.

    Emmo

    • 답변으로 표시됨 mo2000 2012년 4월 1일 일요일 오후 11:31
    •