code_junkie

Can a WPF ListBox be “read only”?

Nov 11th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <ListBox x:Name="_listBox">
  2. <ListBox.ItemContainerStyle>
  3. <Style TargetType="ListBoxItem">
  4. <Setter Property="IsEnabled" Value="False"/>
  5. </Style>
  6. </ListBox.ItemContainerStyle>
  7. </ListBox>
  8.  
  9. <ListBox x:Name="_listBox">
  10. <ListBox.ItemContainerStyle>
  11. <Style TargetType="ListBoxItem">
  12. <Setter Property="IsEnabled" Value="False"/>
  13. <Style.Triggers>
  14. <Trigger Property="IsEnabled" Value="False">
  15. <Setter Property="Foreground" Value="Red" />
  16. </Trigger>
  17. </Style.Triggers>
  18. </Style>
  19. </ListBox.ItemContainerStyle>
  20. </ListBox>
  21.  
  22. <ItemsControl DataContext="{Binding Source={StaticResource Things}}" ItemsSource="{Binding}" Margin="0">
  23. <ItemsControl.Resources>
  24. <local:SelectedConverter x:Key="conv"/>
  25. </ItemsControl.Resources>
  26. <ItemsControl.ItemsPanel>
  27. <ItemsPanelTemplate>
  28. <local:Control Background="{Binding Path=IsSelected, Converter={StaticResource conv}}"/>
  29. </ItemsPanelTemplate>
  30. </ItemsControl.ItemsPanel>
  31.  
  32. private void lstSMTs_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  33. {
  34. e.Handled = !editRights;
  35. }
Add Comment
Please, Sign In to add comment