在我的 UWP xaml 文件中,我需要在下面的 ScrollViewer 代码中重用 StackPanel,该怎么做?
<StackPanel Orientation="Vertical">
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
</StackPanel>
...
<ScrollViewer
Width="1920"
Height="1020"
HorizontalScrollMode="Enabled"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
</StackPanel>
<StackPanel Orientation="Vertical">
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
</StackPanel>
...
</StackPanel>
</ScrollViewer>
创建一个用户控制 https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.usercontrol并定义StackPanel
there:
<UserControl
x:Class="App1.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<StackPanel Orientation="Vertical">
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
<Button Content="button1" Style="{StaticResource buttonStyle}">
</Button>
</StackPanel>
</UserControl>
然后您可以创建您的多个实例UserControl
在你的ScrollViewer
:
<ScrollViewer
Width="1920"
Height="1020"
HorizontalScrollMode="Enabled"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden">
<StackPanel Orientation="Horizontal">
<local:MyUserControl1 />
<local:MyUserControl1 />
<local:MyUserControl1 />
</StackPanel>
</ScrollViewer>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)