通过转换我的 win 表单应用程序来学习 WPF。目前很难弄清楚如何将 TreeViewItems 添加到在同一行上的文本之前包含图像的 TreeView 中。我的图像是列为资源的 png 文件。
我希望能够指定每个项目的图像和文本。我所看到的一切都在设置默认图像。
非常感谢您的帮助。
谢谢
最佳答案
尝试这样的事情:
<TreeView ItemsSource="{Binding SomeData}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Icon}" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
有关如何绑定(bind)图像的更多详细信息,请参阅以下内容: Binding image source through property in wpf
关于c# - 带有图标和文本的 WPF TreeView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20278898/