我有这个案子
<WrapPanel>
<CheckBox>Really long name</CheckBox>
<CheckBox>Short</CheckBox>
<CheckBox>Longer again</CheckBox>
<CheckBox>Foo</CheckBox>
<Slider MinWidth="200" />
</WrapPanel>
Run Code Online (Sandbox Code Playgroud)
我希望WrapPanel内的所有CheckBox都是相同的宽度.
添加以下内容几乎可以实现所需的效果
<WrapPanel.Resources>
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
<Setter Property="MinWidth" Value="75" />
</Style>
</WrapPanel.Resources>
Run Code Online (Sandbox Code Playgroud)
但是,我不想硬编码特定的宽度,而是让最大的CheckBox设置宽度(如果任何宽度> 75,上面也会失败).
Slider是独立的,应该允许比CheckBox更大.
我不想使用网格(使用IsSharedSizeScope),因为我不想要硬编码的列数.
本文提供了一个有趣的解决方案,但如果不创建自定义控件或使用C#代码就可以解决问题.
最好的方法是什么,最好只在XAML中使用?
有没有办法动态地将列表按钮绑定到一个WrapPanel以及它们的事件?
我有一个元素集合,每个元素都有一个名称和一个图像blob的子集合.我想显示一个Accordion,每个项目代表每个MainElements.在每个元素内部,我在所述MainElement的子集合中显示图像.Accordion会被用户调整大小,因此我使用了一个wrappanel来呈现图像.当手风琴足够宽时,图像重新排序,每个排列的数量与每行中的可能性一致.当wrappanel每行只显示一个图像时会出现问题(因为没有足够的空间可供更多),图像列表会继续,但我看不到所有图像,因为它们不适合控件的高度.我需要在AccordionItem内显示一个垂直滚动条,以便我可以向下滚动图像列表.所以,这是我的代码:
<layoutToolkit:Accordion Width="Auto" Height="Auto" ItemsSource="{Binding MainElementCollection}">
<layoutToolkit:Accordion.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding MainElementName}" />
</DataTemplate>
</layoutToolkit:Accordion.ItemTemplate>
<layoutToolkit:Accordion.ContentTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding SubElementCollection}" ScrollViewer.VerticalScrollBarVisibility="Auto" >
<ItemsControl.Template>
<ControlTemplate>
<controlsToolkit:WrapPanel />
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Image Margin="2" Width="150" Source="{Binding PreviewImage, Converter={StaticResource ImageConverter}}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</layoutToolkit:Accordion.ContentTemplate>
</layoutToolkit:Accordion>
Run Code Online (Sandbox Code Playgroud)
http://www.silverlightshow.net/tips/How-to-add-scrollbars-to-ItemsControl.aspx建议我应该用一个scrollviewer环绕我的wrappanel,就像这样
<ItemsControl.Template>
<ControlTemplate>
<scrollviewer>
<controlsToolkit:WrapPanel />
</scrollviewer>
</ControlTemplate>
</ItemsControl.Template>
Run Code Online (Sandbox Code Playgroud)
但是后来我的包装变得非常小,我只能看到一个小的垂直滚动条任何想法?非常感谢.
编辑:我认为当在controltemplate中使用时,wrappanel会失去其宽度
它应该如下使用:
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel ScrollViewer.VerticalScrollBarVisibility="Visible" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)
无论如何,我尝试添加ScrollViewer.VerticalScrollBarVisibility ="Visible"行,但我又被卡住了.
再次编辑:
现在我的包装袋看起来像这样:
<ItemsControl ItemsSource="{Binding StageVideos}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate> …Run Code Online (Sandbox Code Playgroud) silverlight wrappanel itemtemplate itemscontrol scrollviewer
我有一个奇怪的问题.
情况就是这样.我有一个ListView定制的自定义GroupStyle,使数据显示在Expanders中,其中有一个WrapPanel包含StackPanels(包含一个ToggleButton +一个自定义控件)StackPanel默认情况下,自定义控件不可见,并在ToggleButton选中时显示.但是,当我检查a时ToggleButton,会出现自定义控件,位于同一行的所有其他控件将移动到垂直中心.理想情况下,我希望其他成员能够保持领先地位.我试着尽VerticalAlignment="Top"我所能,不管怎样都不会改变.
成像问题:
扩展器的初始状态:

一旦ToggleButton被点击时,会出现以下情况:

如您所见,"测试分析"按钮移动到中心位置.我希望它与原版保持在同一个地方.
而且,我已经在单独的DataTemplates对象中定义了所有这些样式.这里有一些轻量代码(我刚刚删除了这里的问题无用,不会让你阅读大量的XAML代码:)):
扩展器的内容属性:
<Expander.Content>
<WrapPanel Background="White" VerticalAlignment="Top">
<ItemsPresenter VerticalAlignment="Top"/>
</WrapPanel>
</Expander.Content>
Run Code Online (Sandbox Code Playgroud)
清单的ItemsPanel:
<ItemsPanelTemplate >
<WrapPanel
Width="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource
AncestorType=Expander}}"
ItemWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
Run Code Online (Sandbox Code Playgroud)
清单的ItemsTemplate:
<StackPanel Orientation="Vertical" Height="Auto" Width="Auto" VerticalAlignment="Top" >
<ToggleButton BorderBrush="{x:Null}" Background="{x:Null}" IsChecked="{Binding Value.IsToLaunch, Mode=TwoWay}"
Command="{Binding DataContext.UpdateGroupCheckingsCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"> …Run Code Online (Sandbox Code Playgroud) 我正在使用 WrapPanel 并且因为我想节省空间,所以我想根据某些功能删除(而不是隐藏)一些控件(其中一些是组框)。
我应该使用什么命令来删除控件?
我有一个 ScrollViewer,里面有一个 ItemsControl。ItemsControl 的 ItemSource 绑定到 ObservableCollection。
问题是它将所有内容默认为一列。我希望根据窗口的大小,子项将适应所有可用区域。
WrapPanel 会起作用。请看下图。在左侧,项目排列在 ItemsPanel 内,在右侧,它们排列在 WrapPanel 内。
但不幸的是,WrapPanel 没有 ItemSource 属性,因此我可以绑定我的项目。有没有办法让 ItemsSource 有更多的列或将我的 ObservableCollection 绑定到 WrapPanel?
我有一个在 a 内ItemsControl显示一堆 的。这非常有效,除非我有一堆用户控件,然后溢出会呈现在屏幕外,并且我无法访问它。我的目标是让 WrapPanel 水平换行,但是一旦控件离开屏幕,就会显示滚动条,这似乎对我不起作用。UserControlWrapPanel
<ItemsControl ItemsSource="{Binding Servers, Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness="1" Margin="5,5,5,5">
<local:ServerControl DataContext="{Binding }" /> <!-- The actual UserControl -->
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
当应用程序第一次启动时,这就是它的样子。如果应该查看 14 个盒子,您将看不到什么。WrapPanel 正在执行其工作,但它被渲染到窗口边界之外。
这显示了所有用户控件,但我必须扩展窗口才能看到它们。
任何帮助将不胜感激。
完整的 XAML:
<Window x:Class="ServerMonitor.Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ServerMonitor.Wpf"
xmlns:models="clr-namespace:ServerMonitor.Wpf.Models"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Leading Hedge Server Monitor" Height="350" Width="800">
<Window.DataContext>
<models:MainWindowViewModel>
<models:MainWindowViewModel.MachineNames>
<!-- Test Servers -->
<System:String>T009</System:String>
<System:String>T010</System:String>
<System:String>T011</System:String>
<System:String>T012</System:String>
</models:MainWindowViewModel.MachineNames>
</models:MainWindowViewModel>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition …Run Code Online (Sandbox Code Playgroud) 我有一个 WrapPanel,我正在用 UserControls 填充我的 ViewModel:
<WrapPanel Width="250" Orientation="Horizontal" Margin="3">
<ItemsControl ItemsSource="{Binding PlaceableObjectsContent}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:PlaceableObjectViewModel}">
<local:PlaceableObjectUserControl>
<local:PlaceableObjectUserControl.InputBindings>
<MouseBinding MouseAction="LeftClick"
Command="{Binding DataContext.OnPlaceableObjectClicked, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
CommandParameter="{Binding}"/>
</local:PlaceableObjectUserControl.InputBindings>
</local:PlaceableObjectUserControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</WrapPanel>
Run Code Online (Sandbox Code Playgroud)
当我用随机控件填充它们时,一切正常!我已经阅读了一些关于由于使用 ItemTemplate 的问题!?如果是真的,我该如何管理?
谢谢

我有一个WrapPanel(绿色背景)ListBox(灰色背景).
我试图动态添加StackPanel多次(通过点击给定图像下面的按钮)WrapPanel.
该StackPanel包含Button哪些内容具有"X".StackPanel单击此按钮时,我想删除单个对象(橙色背景).
怎么能解决?
如何创建布局容器,我可以作为使用ItemsPanel的ItemsControl
是堆叠在两列的项目,并使用正确的列未在左边的列(足够的空间像一个统一的网格包裹混合剩余项目面板)。
例如:
高度几乎相同的四个项目将显示如下:

其中两个宽度明显较小的四个项目将显示如下:

在silverlight中将子项添加到WrapPanel的最佳方法是什么?我正在使用C#,我正在读取包含缩略图和相关信息的图像的JSON对象.
最终目标是有一个缩略图网格(水平13个拇指横跨950像素×6个拇指垂直).
我有以下XAML代码:
<DataTemplate x:Key="FriendsDataTemplate">
<toolkit:WrapPanel Orientation="Horizontal" ItemWidth="173" ItemHeight="233">
<Grid VerticalAlignment="Top" HorizontalAlignment="Right">
<Grid.RowDefinitions>
<RowDefinition Height="183"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Image x:Name="FriendAvatar" Margin="1,1,11,11" Source="{Binding ImageURL}" Width="173" Height="173"/>
<Grid Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Top">
<TextBlock x:Name="FriendName" Margin="0" Text="{Binding FriendName}" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="0,0,10,0" TextAlignment="Right"/>
</Grid>
</Grid>
</toolkit:WrapPanel>
</DataTemplate>
<Grid x:Name="FriendsGrid">
<ListBox x:Name="FriendsList" Margin="0" ItemTemplate="{StaticResource FriendsDataTemplate}"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
FriendsList 宽度为420px.
我的问题是:我想要两个项目列,但我看到一个.
有什么建议?
wrappanel ×12
wpf ×9
c# ×5
itemscontrol ×5
itemtemplate ×2
scrollviewer ×2
silverlight ×2
xaml ×2
.net ×1
binding ×1
controls ×1
datatemplate ×1
json ×1
layout ×1
stackpanel ×1
uniformgrid ×1
wpf-controls ×1