wpf程序中TreeView图标显示不全
具体操作为:动态在treeview的imagelist中添加图片,然后再添加到node上。程序是wpf程序,其中treeview的容器为为usercontro,是一个Fo...
具体操作为:动态在treeview的imagelist中添加图片,然后再添加到node上。程序是wpf程序,其中treeview的容器为为usercontro,是一个Form和wpf混合应用的程序。l
源码为:
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
TreeNode node = new TreeNode();
node.Name = openFileDialog1.FileName;
node.Text = openFileDialog1.FileName;
node.ImageKey = GetImageKey(openFileDialog1.FileName);
node.SelectedImageKey = GetImageKey(openFileDialog1.FileName);
treeView1.Nodes[0].Nodes.Add(node);
Application.DoEvents();
treeView1.Refresh();
}
}
private string GetImageKey(string imagepath)
{
string imagekey = imagepath;
if (!imageList1.Images.ContainsKey(imagekey))
{
Image img = Image.FromFile(imagepath);
imageList1.Images.Add(imagekey,img);
Application.DoEvents();
}
return imagekey;
} 展开
源码为:
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
TreeNode node = new TreeNode();
node.Name = openFileDialog1.FileName;
node.Text = openFileDialog1.FileName;
node.ImageKey = GetImageKey(openFileDialog1.FileName);
node.SelectedImageKey = GetImageKey(openFileDialog1.FileName);
treeView1.Nodes[0].Nodes.Add(node);
Application.DoEvents();
treeView1.Refresh();
}
}
private string GetImageKey(string imagepath)
{
string imagekey = imagepath;
if (!imageList1.Images.ContainsKey(imagekey))
{
Image img = Image.FromFile(imagepath);
imageList1.Images.Add(imagekey,img);
Application.DoEvents();
}
return imagekey;
} 展开
1个回答
2011-07-06
展开全部
<TreeView.ItemTemplate>
<DataTemplate>
<DockPanel>
<CheckBox/>
<TextBlock Text=""/>
</DockPanel>
</DataTemplate>
</TreeView.ItemTemplate>
另外,团IDC网上有许多产品团购,便宜有口碑
<DataTemplate>
<DockPanel>
<CheckBox/>
<TextBlock Text=""/>
</DockPanel>
</DataTemplate>
</TreeView.ItemTemplate>
另外,团IDC网上有许多产品团购,便宜有口碑
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询