我需要显示Buttons
,用户可以使用它添加控件。 Buttons
按组分类。这是我正在使用的XAML -
<ScrollViewer
VerticalScrollBarVisibility="Auto">
<GroupBox
Name="maingroup"
Header="Click To Add Controls"
BorderBrush="Transparent">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="90" />
</Grid.RowDefinitions>
<GroupBox
Grid.Row="0"
Name="groupVarControls"
Header="{Binding Path=GroupBoxHeaderText, Mode=OneWay}">
<ScrollViewer
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Hidden">
<WrapPanel
Margin="7,7,0,0"
AllowDrop="False">
<syncfusion:RibbonButton
SizeForm="Large"
Name="BarControl"
LargeIcon="Images\Bar.png"
Label="Bar"
AllowDrop="True">
</syncfusion:RibbonButton>
<!-- 10 More buttons -->
</WrapPanel>
</ScrollViewer>
</GroupBox>
<GroupBox
Grid.Row="1"
Name="groupVarControls2"
Visibility="{Binding Path=GroupBoxVisibility, Mode=OneWay}"
Header="Click to Add control">
<ScrollViewer
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Auto">
<WrapPanel
Margin="7,7,0,0"
AllowDrop="False">
<syncfusion:RibbonButton
SizeForm="Large"
Name="ClockControl"
AllowDrop="False"
LargeIcon="Images\Clock.png"
Label="Clock"
Click="ClockControl_Click" />
<!-- More buttons -->
</WrapPanel>
</ScrollViewer>
</GroupBox>
</Grid>
</GroupBox>
</ScrollViewer>
我希望ScrollBar
和个别水平WrapPanel
的常见垂直ScrollBar
。由于此XAML滚动条未正确显示,ScrollViewer
导致包装被“禁用”,它只会将我的控件保留在单个row
(或column
)中,并使用{{ 1}}马上。
我无法将固定ScrollBar
提供给widht
,因为此控件将显示在WrapPanel
(类似于VS工具箱)中,用户可以使用它。
有什么想法吗?
答案 0 :(得分:2)
此代码将在需要时显示一个垂直滚动条和两个水平滚动条。在您的代码中,您需要将包装面板的MinWidth设置为最宽子项的宽度。您可以在代码中轻松地执行此操作,以便在用户添加或删除控件时进行处理。
<ScrollViewer
VerticalScrollBarVisibility="Auto">
<StackPanel>
<GroupBox Header="Box 1">
<ScrollViewer
VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Auto">
<WrapPanel
MinWidth="200"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}">
<Button Width="200" Height="50" />
<Button Width="150" Height="50" />
<Button Width="160" Height="50" />
<Button Width="170" Height="50" />
<Button Width="180" Height="50" />
</WrapPanel>
</ScrollViewer>
</GroupBox>
<GroupBox Header="Box 2">
<ScrollViewer
VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Auto">
<WrapPanel
MinWidth="200"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}">
<Button Width="200" Height="50" />
<Button Width="150" Height="50" />
<Button Width="160" Height="50" />
<Button Width="170" Height="50" />
<Button Width="180" Height="50" />
</WrapPanel>
</ScrollViewer>
</GroupBox>
</StackPanel>
</ScrollViewer>