C# 如何按代码设置ListView ItemsStackPanel方向?
通过C# 如何按代码设置ListView ItemsStackPanel方向?,c#,xaml,uwp,uwp-xaml,C#,Xaml,Uwp,Uwp Xaml,通过XAML这很简单,但是如何通过C#做到这一点呢?需要在水平方向和垂直方向之间更改方向 <ListView x:Name="MyListView"> <ListView.ItemsPanel> <ItemsPanelTemplate> <ItemsStackPanel Orientation="Horizontal"/> </ItemsPanelTemplate>
XAML
这很简单,但是如何通过C#
做到这一点呢?需要在水平方向和垂直方向之间更改方向
<ListView x:Name="MyListView">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
好的。问题解决了。下一个代码运行良好
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;
}