C# 在wrappanel中添加动态按钮wpf
我试图在屏幕上动态显示一个环绕面板中的按钮,这样它们就可以在没有任何滚动条的情况下很好地放置在屏幕上。我有如下的标记,但是由于某些原因出现了滚动条。我们如何使滚动条不出现,按钮没有任何滚动条C# 在wrappanel中添加动态按钮wpf,c#,wpf,button,dynamic,wrappanel,C#,Wpf,Button,Dynamic,Wrappanel,我试图在屏幕上动态显示一个环绕面板中的按钮,这样它们就可以在没有任何滚动条的情况下很好地放置在屏幕上。我有如下的标记,但是由于某些原因出现了滚动条。我们如何使滚动条不出现,按钮没有任何滚动条 <ListBox x:Name="ItemsListBox" > <ListBox.ItemTemplate> <DataTemplate> <ToggleButton
<ListBox x:Name="ItemsListBox" >
<ListBox.ItemTemplate>
<DataTemplate>
<ToggleButton Content="{Binding Name}" Click="Click" MinWidth="120" MinHeight="70" FontWeight="Bold" FontSize="18"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel></WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
添加
给您的容器。您的
列表框内有什么控件?您描述的问题通常是由父控件导致的,该父控件允许ListBox
增长
您可以通过在列表框
上设置显式的Width=“200”
并测试发生了什么来证明这是否是问题。如果它是包装的,那么问题是列表框的父对象。这就是我试图实现的目标
<ItemsControl x:Name="ListBox" Grid.Row="5" Grid.ColumnSpan="2">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton Content="{Binding Name}" MinWidth="120" MinHeight="50" FontWeight="Bold" FontSize="16" Margin="5"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl x:Name="ListBox" Grid.Row="5" Grid.ColumnSpan="2">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton Content="{Binding Name}" MinWidth="120" MinHeight="50" FontWeight="Bold" FontSize="16" Margin="5"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>