在列表框中通过上下文菜单显示传递的文件的路径.[WPF] [英] Show passed file's paths by context menu in a listbox.[WPF]

查看:81
本文介绍了在列表框中通过上下文菜单显示传递的文件的路径.[WPF]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎,我的问题很容易解决,当然只有它,也许不是  :)
假设我们在窗口中有一个列表框,并且可以通过右键单击上下文菜单来运行我们的程序.假设用户选择了多个文件,然后在右键单击上下文菜单中选择我们的应用程序,我现在希望我的应用程序仅运行一个实例(此 被互斥锁保护,并在列表框中显示传递给程序的所有文件路径(这是我的主要问题).

it seems, my problem has easy solution, of course only it seems, maybe not  :)
suppose we have a listbox inside a window, and our program can be run by right click context menu. imagine that the user selects multiple files and then in the right click context menu select our app, i want at this moment, my app run only single instance(this is sloved by mutex) and show all file's paths that passed to program in the listbox(this is my main problem).

谢谢.

推荐答案

您的窗口中有一个列表框.

You have a listbox in your window.

您想查看其中的文件路径.

You want to see the paths of files in it.

显而易见,要做的就是在填充列表框时将文件的路径放入其中.

The obvious thing to do is to put the paths of files in it when you fill the listbox.

或者这不是你的意思吗?

Or is that not what you mean?

如果您的意思是已经在其中,并且想要显示一些直观的迹象表明程序正在为该文件运行,则将列表框绑定到对象的集合,而不仅仅是字符串.

If you mean you already have the path in there and want to show some visual indication the program is running for that file then bind your listbox to a collection of an object rather than just a string.

包括文件名和画笔的属性.

Include properties for file name and a brush.

在处理该对象时,将画笔设置为红色画笔或其他东西.

Set the brush to a red brush or something when that object is being processed.

将画笔绑定到列表框项目的背景.

Bind the brush to background of your listboxitem.

    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="Background" Value="{Binding StateBrush}}"/>
        </Style>
    </ListBox.ItemContainerStyle>

在这里,我将其称为画笔StateBrush.

Here I've called the brush StateBrush.

最初将其设为白色.


这篇关于在列表框中通过上下文菜单显示传递的文件的路径.[WPF]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆