我有一个列表视图,它是绑定到名为FolderItem的类的数据。我只是在后面的代码中设置DataContext。
根据某些条件,我想禁用某些ListViewItems
,以便无法选择它。我是否需要向下钻取树以获取要禁用的项目?如果是这样,任何关于如何做的链接或指针都会有所帮助。或者还有其他方法吗?
修改
<ListView x:Name="FolderListView" ItemsSource="{Binding}" ItemContainerStyle="{StaticResource ListViewItemStyle1}" SelectionChanged="SelectionChanged" IsTapEnabled="True" SelectionMode="Single" AllowDrop="False" CanDragItems="False" IsSwipeEnabled="False">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="60" Width="380" Margin="0,0,0,1" >
<Grid x:Name="ItemGrid" HorizontalAlignment="Left" VerticalAlignment="Center" Width="380" Height="60" >
<TextBlock x:Name="titleTextBlock" Foreground="Black" Text="{Binding FolderText}" Margin="20,0,0,0" VerticalAlignment="Center" TextAlignment="Left" FontSize="25" >
</TextBlock>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
这是ListViewItemStyle1
<Style x:Key="ListViewItemStyle1" TargetType="ListViewItem">
<Setter Property="IsEnabled" Value="{Binding IsItemEnabled}"/>
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="Background" Value="{Binding ItemBgBrush}"/>
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="IsHoldingEnabled" Value="False"/>
<Setter Property="Margin" Value="{ThemeResource ListViewItemMargin}"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
</<Style>
我已将IsEnabled属性与类绑定。但似乎没有效果。是因为我定义了<ListView.ItemTemplate>??