C# 右键单击列表框中的文件时如何标记文件
我的列表框中有文件,当我右键单击列表框中的文件时,我希望该文件将被标记,我该如何做C# 右键单击列表框中的文件时如何标记文件,c#,wpf,C#,Wpf,我的列表框中有文件,当我右键单击列表框中的文件时,我希望该文件将被标记,我该如何做 <Window x:Class="myTool.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="myTool" AllowsTra
<Window x:Class="myTool.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="myTool" AllowsTransparency="False" Icon="/myTool;component/Images/Organize.ico" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="594" Width="512" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" >
<ListBox Height="95" HorizontalAlignment="Left" Margin="78,35,0,0" Name="listBoxFiles" VerticalAlignment="Top" Width="323" Grid.ColumnSpan="2" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionMode="Multiple" PreviewMouseRightButtonDown="listBoxFiles_PreviewMouseRightButtonDown" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_DoubleClick" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete" PreviewMouseDown="MenuItem_PreviewMouseDown" Click="MenuItemDelete_Click"></MenuItem>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
可以通过实现自定义附加行为来扩展
ListBoxItem
行为:添加右按钮选择特性。有关附加行为的详细信息:
用法(XAML):附加的行为应应用于ListBox
的ListBoxItem
s
请用定义了ListBoxItemBehavior
类的命名空间的全名替换BEHAVIOR\u NAMESPACE
<Window ...
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Behaviors="clr-namespace:BEHAVIOR_NAMESPACE">
<ListBox ...
SelectionMode="Multiple">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Behaviors:ListBoxItemBehavior.IsEnabled" Value="True" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</Window>
希望这能有所帮助。您能更好地解释一下如何标记文件吗?当您单击列表框中的项目时,它会变成蓝色,这就是我的意思。标记编辑无法识别该行我应该写什么?(我的列表框属性在第一条注释中)'Behaviors:ListBoxItemBehavior'未找到。定义了
ListBoxItemBehavior
类的命名空间的全名是什么?我不明白您在添加这两行之后问了什么。我收到了许多错误,例如当前上下文中不存在名称'all my controls',请查看没有这两行的我的更新(列表框和窗口)
<Window ...
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Behaviors="clr-namespace:BEHAVIOR_NAMESPACE">
<ListBox ...
SelectionMode="Multiple">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Behaviors:ListBoxItemBehavior.IsEnabled" Value="True" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</Window>