C# 从Windows phone中的父项在ItemsPanelTemplate内绑定

C# 从Windows phone中的父项在ItemsPanelTemplate内绑定,c#,xaml,windows-phone-7.1,itemspaneltemplate,C#,Xaml,Windows Phone 7.1,Itemspaneltemplate,我想更改ItemsPanelTemplate内StackPanel的方向。。。为了改变方向,我实现了一个属性。。有没有办法改变StackPanel的方向。我尝试了以下代码。。但它并没有成功 <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel Orientation="{Binding MyOrient

我想更改ItemsPanelTemplate内StackPanel的方向。。。为了改变方向,我实现了一个属性。。有没有办法改变StackPanel的方向。我尝试了以下代码。。但它并没有成功

<Setter Property="ItemsPanel">
    <Setter.Value>
        <ItemsPanelTemplate>
             <StackPanel Orientation="{Binding MyOrientation,RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Left" />
        </ItemsPanelTemplate>
    </Setter.Value>
</Setter>       

用于
控制模板


请参阅一些示例

使用
{RelativeSource AncestorType=yoursitemscontroltype}

MyItemsControl.cs:

namespace MyNamespace.Controls
{
    public partial class MyItemsControl : ItemsControl
    {
        public static readonly DependencyProperty MyOrientationProperty =
            DependencyProperty.Register(
            "MyOrientation",
            typeof(Orientation),
            typeof(MyItemsControl));

        public Orientation MyOrientation
        {
            get { return (Orientation)GetValue(MyOrientationProperty); }
            set { SetValue(MyOrientationProperty, value); }
        }
    }
}
MyItemsControls.xaml

<Style xmlns:source="clr-namespace:MyNamespace.Controls" TargetType="source:MyItemsControl">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel 
                    Orientation="{Binding Orientation, 
                        RelativeSource={
                            RelativeSource AncestorType=source:MyItemsControl
                        }
                    }"
                    HorizontalAlignment="Left" />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>


参考:

我想更改ItemsPanelTemplate内StackPanel的方向。但是您给出的帖子对我没有帮助。。。抱歉..示例提供了一些使用此的想法,但不完全适用于您的查询。。所以我告诉你,参考样品。