如何按代码设置ListView ItemsStackPanel方向?

时间:2018-05-27 15:03:25

标签: c# xaml uwp uwp-xaml

XAML这很简单,但C#如何做到这一点?需要在OrientationHorizontal之间更改Vertical

<ListView x:Name="MyListView">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsStackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

1 个答案:

答案 0 :(得分:1)

确定。问题解决了。下一个代码效果很好。

        if(MyListView != null)
        {
            ListView ListViewInfo = MyListView;
            ItemsStackPanel ItemsStackPanelInfo = ListViewInfo.ItemsPanelRoot as ItemsStackPanel;
            if ("something is true or false") ItemsStackPanelInfo.Orientation = Orientation.Horizontal;
            else ItemsStackPanelInfo.Orientation = Orientation.Vertical;
        }