Expression Blend 树视图中的图标
我正在习惯使用 Expression Blend,但有一件事情我正在尝试做,但我一生都无法弄清楚。
我想要一棵树,其中每个文本项在文本之前都有一个图标(尝试创建类似文件夹树视图的内容)。我创建了一个示例数据源,每个项目都有两个属性。一张图像和一行文字。问题是图标不是在文本之前,而是图标非常大并且在文本之前有一个新行。我该如何纠正这个问题?感谢您的帮助!
您可以在这里看到我得到的内容:https://i.sstatic.net/V6TGJ.png
编辑:
我找到的解决方案涉及编辑 MainWindow.xaml。我将数据选项卡中的属性名称设置为“TreeIcon”和“TreeLabel”,然后向堆栈面板添加了方向属性,并将图标高度/宽度更改为更合适的值:
<StackPanel Orientation="Horizontal">
<Image Source="{Binding TreeIcon}" HorizontalAlignment="Left" Height="24" Width="32"/>
<TextBlock Text="{Binding TreeLabel}"/>
</StackPanel>
没有“方向”属性,它默认为垂直,因此将其设置为“水平”可以正确定位图标和文本。将图像高度设置为 24 可以使图标的大小大致适合其旁边的文本。宽度设置为 32 是因为当宽度设置为 24 时,图标和文本直接相邻,根本没有填充。将宽度提高到 32,向左侧填充一些内边距。
I'm getting settled in with using Expression Blend, and there is one thing I am trying to do that I can not figure out for the life of me.
I want to have a tree where each text item has an icon before the text (trying to create something like a folder tree view). I created a sample data source and each item has two properties. An image and a line of text. the problem is that rather than the icon being before the text, the icon is really big and has a new line before the text. How do I correct this? Thanks for your help!
You can see what I'm getting here: https://i.sstatic.net/V6TGJ.png
Edit:
The solution I came to involved editing the MainWindow.xaml. I set the property names in the data tab to 'TreeIcon' and 'TreeLabel', then I added an orientation attribute to the stackpanel and changed the icon height/width to something more agreeable:
<StackPanel Orientation="Horizontal">
<Image Source="{Binding TreeIcon}" HorizontalAlignment="Left" Height="24" Width="32"/>
<TextBlock Text="{Binding TreeLabel}"/>
</StackPanel>
Without the 'Orientation' attribute, it defaulted to vertical, so setting it to 'Horizontal' got the icon and text positioned properly. Setting the image height to 24 makes the icon roughly a good size for the text it's next to. The width is set to 32 because when it was at 24, the icon and the text were directly next to each other, with no padding at all. Upping the width to 32 padded some padding to the left.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 silverlight 还是 WPF?您是否查看过样式模板来查找内容控件,并查看它们是否设置了 maxheight 或 maxwidth 属性,也许还设置了水平方向的堆栈面板?
Is this silverlight or WPF? Have you looked at your style template to find the content controls and see if they're set with a maxheight or maxwidth property and perhaps a stackpanel with Horizontal orientation?