我正在使用a WrapPanel作为ItemsPanel一个ItemsControl.现在,控件中的项包装如下:
|1234567 |
|890 |
Run Code Online (Sandbox Code Playgroud)
我希望他们像这样包装:
| 1234567 |
| 890 |
Run Code Online (Sandbox Code Playgroud)
从概念上讲,布局过程应该对齐每一行项目,使其位于范围WrapPanel内.
有人可以解释一下这有可能吗?
我有一个UserControl(下面的XAML),它有一个ListBox,我想在WrapPanel中显示图像,其中图像显示的数量适合一行,然后换行到下一行等.它工作,除了ListBox增长高于窗口中的可用空间,我没有得到垂直滚动条,即内容被剪切.如果我在ListBox上设置固定高度,滚动条将出现并按预期工作.如何让此列表框增长到可用空间,然后显示垂直滚动条?此控件位于主窗口中Grid内的StackPanel内.如果我将StackPanel包装在ScrollViewer中,我会得到我之后的滚动条,但如果我想在ListBox上方的UserControl中添加更多控件(例如图像大小"缩放"等),这不是一个很好的解决方案不希望他们滚动图像.
谢谢!!:)
<UserControl x:Class="GalleryAdmin.UI.GalleryView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ListBox Name="itemListBox" BorderThickness="0" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Background="LightGray" Margin="5" >
<StackPanel Margin="5">
<Image Source="{Binding Path=LocalThumbPath}" Height="100" />
<TextBlock Text="{Binding Path=Name}" TextAlignment="Center"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我有一个简单的WrapPanel包含许多宽控件.当我调整大小Width时,Window一切按预期工作.如果有足够的空间,控件将在一行上进行,或者如果没有,则控件将在下一行中包含.
但是,我需要发生的是,如果所有控件基本上都是垂直堆叠的(因为没有更多的水平空间)并且其中Width的Window更多还是更多,则会出现一个水平滚动条,以便我可以滚动并查看整个控制我是否愿意.下面是我的xaml.我试着把它包裹起来WrapPanel,ScrollViewer但我无法实现我的目标.
<Window x:Class="WpfQuotes.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="Auto" Width="600" Foreground="White">
<WrapPanel>
<Button Width="250">1</Button>
<Button Width="250">2</Button>
<Button Width="250">3</Button>
</WrapPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
因此,如果Width将上述内容减少Window到最小值,您将无法看到按钮的文本.我想要一个水平滚动条出现,以便我可以滚动查看文本,但不会干扰通常的包装功能.
谢谢.
更新:
我已按照下面的保罗建议,水平滚动条现在按预期显示.但是,我也希望垂直滚动可用,所以我设置VerticalScrollBarVisibility="Auto".问题是,如果我调整窗口大小以便显示垂直滚动条,即使不需要(也有足够的水平空间来查看整个控件),也会始终显示水平滚动条.好像出现的垂直滚动条会弄乱滚动查看器的宽度.有没有办法纠正这个问题,除非实际需要水平滚动条,否则不会出现?
下面是我的xaml和我添加的唯一代码CustomWrapPanel:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cwp="clr-namespace:CustomWrapPanelExample"
Title="Window1" Height="Auto" Width="300" Foreground="White" Name="mainPanel">
<ScrollViewer x:Name="MyScrollViewer" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<cwp:CustomWrapPanel Width="{Binding ElementName=MyScrollViewer, Path=ActualWidth}">
<Button Width="250">1</Button>
<Button Width="250">2</Button>
<Button Width="250">3</Button>
<Button Width="250">4</Button>
<Button Width="250">5</Button>
<Button Width="250">6</Button>
<Button Width="250">7</Button>
<Button Width="250">8</Button> …Run Code Online (Sandbox Code Playgroud) 我有一个WrapPanel,我想指定其列的最大数量.因此,例如,当我的Collection"ObjectCollection"(绑定到此WrapPanel)仅包含4个元素时,WrapPanel将只有一行.但是,当"ObjectCollection"将包含5个元素时,wrapPanel将创建另一行以放置第五个元素.(在这种情况下,我的Max_Columns_Number是4).
我有一个ListBox,我的ItemsPanel替换为WrapPanel.WrapPanel现在托管数据绑定ListboxItems.每个项目中都有一个可变大小的文本,为每个项目提供不同的宽度.但是,我希望宽度保持不变,以便所有项目的宽度与文本最长的项目相同.那可能吗?
我需要垂直列出项目(全部大小相同)(使用ScrollViewer).如果容器足够大以显示x列,我希望项目通过x列传播
我第一次尝试:
<ScrollViewer>
<toolkit:WrapPanel Orientation="Horizontal" ItemHeight="30" ItemWidth="100">
<Button Content="1" />
<Button Content="2" />
<Button Content="3" />
<Button Content="4" />
<Button Content="5" />
</toolkit:WrapPanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

结果 - WrapPanel的工作方式与我想的一样,但我的项目是从"从左到右"排序的(不是垂直的
然后我尝试将WrapPanel的Orientation设置为" Vertical ":

结果 - 我的项目是垂直排序但未在多列上展开.
以下是我想要呈现的项目:

我真的想避免编写监视控件大小的代码来创建/删除列,具体取决于它的大小.
我很习惯在WPF工作,但我最近开始用html构建网站.
我想在html中列出一些事物(比方说,每个包含一张图片和一个描述),就像它们在WPF包装中一样.
通过这样做,我想我几乎做对了:
<ul id="listofthings">
<li>
<div class="card">
<div class="image" id="pic1">
</div>
<div class="description">
<h2><a href="">Dog</a></h2>
<p>The dog is a domesticated form of the gray wolf, a member of the Canidae family.</p>
<a href="">Read more.</a>
</div>
</div>
</li>
<li>
<div class="card">
<div class="image" id="pic1">
</div>
<div class="description">
<h2><a href="">Cat</a></h2>
<p>The cat, also known as the domestic cat or housecat, is a small furry domesticated carnivorous mammal.</p>
<a href="">Read more.</a>
</div>
</div>
</li>
<!--...etc. etc.-->
</ul>
Run Code Online (Sandbox Code Playgroud)
并设置这样的CSS:
#listofthings{
background-color:gray;
list-style-type:none;
} …Run Code Online (Sandbox Code Playgroud) 我想创建一个ItemsControl子项目放置的地方WrapPanel,但是子项目应该占用尽可能多的空间.因此,当窗口大小变大或变小时,子项应根据特定的宽度:高度比进行拉伸.当孩子项目将添加或从删除ItemsControl的ItemsSource,则WrapPanel应该适当地放置物品中换行,以保持子项的宽度:高度比率.
以下是我到目前为止的情况.是否可以在Xaml中执行此操作?或者我应该为此创建自定义控件?提前致谢!
<Window>
<Grid>
<ItemsControl ItemsSource="{Binding DataCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" >
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Value}"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Time, StringFormat='hh:mm:ss' }"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 以下示例中的标签(WPF/XAML)只是在屏幕上游行,不会发生包装.删除方向有效,但不提供所需的功能/外观.任何想法如何使WrapPanel包装到当前的大小StackPanel?
<Window Height="300" Width="600">
<StackPanel Orientation="Horizontal">
<WrapPanel>
<Label Height="28" Name="label1" Width="120">First Name</Label>
<Label Height="28" Name="label2" Width="120">John</Label>
<Label Height="28" Name="label3" Width="120">Last Name</Label>
<Label Height="28" Name="label4" Width="120">Smith</Label>
<!-- ...more labels!... -->
</WrapPanel>
<!-- ...other controls/panels... -->
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud) 我安装了Windows 7.
然后,我从此处使用Web Platform Installer安装了Web Developer 2010 Express .
然后我从这里安装了Silverlight 4 Toolkit 的4月15日版本.
然后我添加了这个参考:
替代文字http://www.deviantsart.com/upload/ijk0lm.png
然后在我的XAML中,我像这样引用它,但它没有给我智能感知并且告诉我我缺少一个程序集引用:
替代文字http://www.deviantsart.com/upload/cd4vrj.png
更新:
xmlns:tk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Run Code Online (Sandbox Code Playgroud)
即使在重建之后也不起作用
在Web Developer 2010 Express中使用Silverlight 4 Toolkit需要做什么?
所以我在另一台计算机上用Web Developer Express 2008中的Silverlight 3再次测试它,它确实按照我记忆的方式工作,所以为什么它不能在Silverlight 4中以这种方式工作,我需要更改才能获得它上班?:
wrappanel visual-studio-2010 silverlight-toolkit dockpanel silverlight-4.0
wrappanel ×10
wpf ×8
c# ×3
xaml ×3
.net ×2
layout ×2
listbox ×2
center ×1
css ×1
data-binding ×1
dockpanel ×1
html ×1
itemscontrol ×1
scroll ×1
scrollbar ×1
scrollviewer ×1
silverlight ×1
stackpanel ×1
wpf-controls ×1