c# - 如何在禁用的 ListboxItem 中启用按钮?
问题描述
我在 Wpf 中有一个 ListBox,里面装满了 ListBoxItems - 每个项目都包含一个文件对象和一个“信息按钮”。这些文件对象包含文件属性 - 例如文件名、路径等 - 但其中一些文件是无效的,由标志标记。
我想禁用包含无效文件的列表框项目,但里面的信息按钮除外。
我成功地在无效元素上禁用了整个列表框项,但这不正确,因为每个文件对象(无论是否无效)都包含特定的文件信息。这可以在单击信息按钮时显示。
此代码运行良好,但结果是列表框项内的每个元素都被禁用。我希望启用该按钮元素。
和代码:
<ListBox x:Name="fileNameListBox"
ItemsSource="{Binding FileListViewModel.FilteredFileList, Mode=TwoWay}"
Grid.Row="4" Grid.Column="0"
Margin="0, 0, 0, 5"
HorizontalContentAlignment="Left">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding FileListSelectionChangedCommand}"
CommandParameter="{Binding ElementName=fileNameListBox, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Label Content="{Binding Filename}" FontWeight="Bold"/>
<Label Content="{Binding FilePath}" FontWeight="Light" FontSize="10"/>
<Button x:Name="infoButton" Width="50" Content="Info" FontWeight="Light" FontSize="14" HorizontalAlignment="Left"
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:FileListView}}, Path=DataContext.FileListViewModel.FileInfoClickedCommand }"
CommandParameter="{Binding}" /> <!-- I want this button to be enabled -->
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsValid}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
所以,我的问题是有没有办法启用这些 ListBox 项中的每个按钮?或者我可以用另一个棘手的解决方案来做这个吗?
解决方案
推荐阅读
- mongodb - 查询以查找特定时间和日期范围内的数据
- weblogic-10.x - weblogic.rjvm.PeerGoneException
- r - 如何在 r 中找到加权平均值?
- reactjs - React Redux TypeError:this.props 不是函数
- c# - 如何在 C# 中计算旋转的图像坐标?
- ionic-framework - Ionic Team 是否停止了适用于 android 的 ionic devapp?
- python - python如何获取两个值之间的值
- xaml - 如何去另一个 xaml 页面 xamarin.form FlowListView
- flutter - Flutter 中 After Effects 文件的使用
- react-native - 在将项目传递给客户端之前如何保护 react-native 应用程序中的源代码