2016-06-17 30 views
-3

我想阻止用户编辑/选择组合框。我尝试使用cmbbox.IsReadOnly = Truecmbbox.IsEditable = False,它允许用户通过altarrow' keys更改选择。 cmbbox.isEnabled = False的作品,我的要求是禁用时,将组合框前景颜色更改为“黑色”。任何人都可以请帮我解决它?如何更改禁用状态下组合框的前景?

在XAML:

<telerik:RadComboBox Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" x:Name="combobox1" IsEditable="True" IsFilteringEnabled="True" ItemsSource="{Binding}" TabIndex="7" Style="{ DynamicResource DropDownListStyle }" IsTabStop="True" KeyboardNavigation.TabNavigation ="Local" SelectAllTextEvent="None" Height="23" Margin="0,0,0,2" VerticalAlignment="Center"/> 

在代码隐藏:

combobox1.IsEnabled = False 

风格:

<Style x:Name="DropDownListStyle" x:Key="DropDownListStyle" TargetType="telerik:RadComboBox" > 
       <Setter Property="Foreground" Value="#FF000000"/> 
       <Setter Property="BorderBrush" Value="#ffcccccc"/> 
       <Setter Property="BorderThickness" Value="1"/> 
       <Setter Property="HorizontalContentAlignment" Value="Left" /> 
       <Setter Property="VerticalContentAlignment" Value="Center" /> 
       <Setter Property="FontSize" Value="12"/> 
       <Setter Property="FontWeight" Value="Thin"/> 
       <Setter Property="FontFamily" Value="Trebuchet MS"/> 
       <Setter Property="Panel.ZIndex" Value="10" /> 
       <Setter Property="Height" Value="23" /> 
       <!-- <Setter Property="Focusable" Value="True"/> --> 
       <Style.Triggers> 
        <Trigger Property="IsEnabled" Value="False"> 
         <Setter Property="Background" Value="White"/> 
         <Setter Property="Foreground" Value="Black"/> 
        </Trigger> 
       </Style.Triggers> 
      </Style> 
+0

请分享一下你的代码 –

+0

的事实上,这将是很好的编辑您的问题,并添加到目前为止你写的代码:如何创建一个最小的,完整的,和可验证的例子?](http://stackoverflow.com/help/mcve)。 –

回答

0

我已通过将IsReadonly = True属性设置为combobox并触发PreviewKeyDown事件来修复它。

combobox1.IsReadonly = True 

Private Sub combobox1_PreviewKeyDown(sender As Object, e As Windows.Input.KeyEventArgs) Handles combobox1.PreviewKeyDown 
     If combobox1.IsReadOnly Then 
      If e.Key = Key.Tab Then 
       e.Handled = False 
      Else 
       e.Handled = True 
      End If 
     End If 
End Sub 
0

如果你想防止用户更改此组合框不使用只读或启用您可以在组合框SelectedIndexChanged事件中尝试此操作。

但是没有看到你的代码,我们无法帮助解决特定的问题。

'Inform the user 
MsgBox("You can't change this drop down") 
'Reset any choice 
e.NewValue = e.CurrentValue 

e是在选择所选索引更改事件时传入的事件参数。