如何在绑定的listboxitem上禁用点击事件?
我设法将项目的可见性设置为false,但这还不够,因为即使项目不可见,当单击该区域时它仍然会触发事件。这是我的项目:
<DataTemplate x:Key="stolTemplate1">
<Grid Visibility="{Binding konobar, Converter={StaticResource IsItMyTable}}" Height="155" Width="155">
<Grid.Background>
<ImageBrush ImageSource="{Binding suma, Converter={StaticResource tablePictureConverter}}"/>
</Grid.Background>
<Grid Height="27" Width="Auto" Visibility="{Binding suma, Converter={StaticResource IsItMyTable2}}" VerticalAlignment="Bottom" Margin="45,0,45,128">
<Grid.Effect>
<DropShadowEffect/>
</Grid.Effect>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{DynamicResource tipkeNarPlaG1Color}" Offset="0"/>
<GradientStop Color="#FF1E4D57" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Label Content="{Binding suma}" Foreground="White" HorizontalAlignment="Center" FontWeight="Bold" FontSize="16">
<Label.Effect>
<DropShadowEffect/>
</Label.Effect>
</Label>
</Grid>
<Label x:Name="label" Content="{Binding broj_stola}" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" Height="Auto" Width="Auto" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="Black" FontSize="26.667" Background="{x:Null}" FontWeight="Bold"/>
</Grid>
</DataTemplate>
此部分:
<Grid Visibility="{Binding konobar, Converter={StaticResource IsItMyTable}}"
调用此部分:
Private Function IValueConverter_Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If value = Globals.konobar Or value = 0 Then Return Visibility.visible
Return Visibility.Collapsed
End Function
我希望它不是Isvisible = IsEnabled = False / True。
我是通过ItemTemplate还是通过ItemContainer实现此目标?
答案 0 :(得分:0)
好吧,有几种方法可以做到这一点:
快速又肮脏:为 IsEnabled 属性
创建一个额外的转换器 <Grid Visibility="{Binding konobar, Converter={StaticResource IsItMyTable}, IsEnabled={StaticResource YOUR_ISENABLED_CONVERTER}}"
在视图模型中创建一个布尔值,并将其绑定到您的Visibility和IsEnabled / IsHitTestVisible属性
创建一个依赖项属性(“ propdp”代码段)并将其绑定到您的属性
根据您的特定需求创建附加属性/行为
IMO,最好在您的视图模型中执行所有“逻辑约束”。