如何通过代码设置ListView ItemsStackPanel方向?
How to set ListView ItemsStackPanel orientation by code?
这对 XAML
来说很简单,但是 C#
如何做到这一点呢?需要在 Horizontal
和 Vertical
之间更改 Orientation
。
<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;
}
这对 XAML
来说很简单,但是 C#
如何做到这一点呢?需要在 Horizontal
和 Vertical
之间更改 Orientation
。
<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;
}