1

ContentControl と ItemsControl の 2 つの部分を含むカスタム Silverlight テンプレート コントロールを作成しました。カスタム テンプレート コントロール内で動作するテンプレートを正常に作成しましたが、パーツの内部テンプレートを Blend に公開して、編集し、既定値で公開できるようにしたいと考えています。

これを機能させるために、次のコードのさまざまなバリエーションを試しましたが、成功しませんでした。

    [TemplatePart(Name = ExpanderTemplateControl2.PartName_FullViewItem, Type = typeof(ExpanderFullViewItem))]
[TemplatePart(Name = ExpanderTemplateControl2.PartName_ItemsControl, Type = typeof(ItemsControl))]
public class ExpanderTemplateControl2 : Control
{
    public const string PartName_FullViewItem = "PART_FullViewItem";
    public const string PartName_ItemsControl = "PART_ItemsControl";

    #region Parts

    private ContentControl part_FullViewItem;
    private ItemsControl part_ItemsControl;

    #endregion


    static ExpanderTemplateControl2()
    {
        //DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomListControl), new FrameworkPropertyMetadata(typeof(CustomListControl)));

        //Add Ownership of dependency property
        ItemTemplateProperty = ItemsControl.ItemTemplateProperty;//.AddOwner(typeof(ExpanderTemplateControl2));
        ItemsPanelProperty = ItemsControl.ItemsPanelProperty;//.AddOwner(typeof(ExpanderTemplateControl2));
        FullViewTemplateProperty = ContentControl.TemplateProperty;//.AddOwner(typeof(ExpanderTemplateControl2));
    }

    public ExpanderTemplateControl2()
    {
        this.DefaultStyleKey = typeof(ExpanderTemplateControl2);
    }


    #region Dependency Properties

    public static readonly DependencyProperty ItemTemplateProperty;
        //= DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(ExpanderTemplateControl2), new PropertyMetadata(null));

    public static readonly DependencyProperty ItemsPanelProperty;
        //= DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(ExpanderTemplateControl2), new PropertyMetadata(null));

    public static readonly DependencyProperty FullViewTemplateProperty;
        //= DependencyProperty.Register("FullViewItemTemplate", typeof(ControlTemplate), typeof(ExpanderTemplateControl2), new PropertyMetadata(null));

    #endregion



    #region Properties

    [BindableAttribute(false)]
    public DataTemplate ItemTemplate
    {
        get { return (DataTemplate)GetValue(ItemTemplateProperty); }
        set { SetValue(ItemTemplateProperty, value); }
    }

    [BindableAttribute(false)]
    public ItemsPanelTemplate ItemsPanel 
    {
        get { return (ItemsPanelTemplate)GetValue(ItemsPanelProperty); }
        set { SetValue(ItemsPanelProperty, value); }
    }

    [BindableAttribute(false)]
    public ControlTemplate FullViewTemplate
    {
        get { return (ControlTemplate)GetValue(FullViewTemplateProperty); }
        set { SetValue(FullViewTemplateProperty, value); }
    }

    #endregion
}

誰かが私にいくつかの指針を与えることができますか?

乾杯

トリスタン

更新:次のことを行うことで、ある種の動作状態にすることができましたが、満足していません。より良い方法はありますか?

        #region Dependency Properties

    public static readonly DependencyProperty ItemTemplateProperty
            = DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(ExpanderTemplateControl2), new PropertyMetadata(null));

    public static readonly DependencyProperty ItemsPanelProperty
            = DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(ExpanderTemplateControl2), new PropertyMetadata(null));

    public static readonly DependencyProperty FullViewTemplateProperty
            = DependencyProperty.Register("FullViewTemplate", typeof(ControlTemplate), typeof(ExpanderTemplateControl2), new PropertyMetadata(null));

    #endregion

    #region Properties

    [BindableAttribute(false)]
    public DataTemplate ItemTemplate
    {
        get 
        {
            var result = (DataTemplate)GetValue(ItemTemplateProperty);

            if (result == null)
            {
                SetValue(ItemTemplateProperty, part_ItemsControl.ItemTemplate);
                result = part_ItemsControl.ItemTemplate;
            }

            return result; 
        }
        set 
        {
            part_ItemsControl.ItemTemplate = value;
            SetValue(ItemTemplateProperty, value);
        }
    }

    [BindableAttribute(false)]
    public ItemsPanelTemplate ItemsPanel
    {
        get 
        { 
            var result = (ItemsPanelTemplate)GetValue(ItemsPanelProperty);

            if (result == null)
            {
                SetValue(ItemsPanelProperty, part_ItemsControl.ItemsPanel);
                result = part_ItemsControl.ItemsPanel;
            }

            return result; 
        }
        set 
        {
            part_ItemsControl.ItemsPanel = value;
            SetValue(ItemsPanelProperty, value);
        }
    }

    [BindableAttribute(false)]
    public ControlTemplate FullViewTemplate
    {
        get 
        {
            var result = (ControlTemplate)GetValue(FullViewTemplateProperty);

            if (result == null)
            {
                SetValue(FullViewTemplateProperty, part_FullViewItem.Template);
                result = part_FullViewItem.Template;
            }

            return result; 
        }
        set 
        {
            part_FullViewItem.Template = value;
            SetValue(FullViewTemplateProperty, value); 
        }
    }

    #endregion
4

0 に答える 0