This is a migrated thread and some comments may be shown as answers.

Can't get IsEnabled on Item to work

6 Answers 827 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 09 Apr 2015, 05:53 PM

I've had a standard ComboBox working with this code:

 

<ComboBox
    x:Name="comboWindow1"
    SelectedValue="{Binding Window1Page}"
    ItemsSource="{Binding listDashData, UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="ddDashDescription"
    SelectedValuePath="ddDashName"
    SelectionChanged="comboWindow1_SelectionChanged">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="{x:Type ComboBoxItem}">
            <Setter Property="IsEnabled" Value="{Binding ddDashEnabled}"/>
        </Style>
    </ComboBox.ItemContainerStyle>
</ComboBox>

I switched over to the RadComboBox, thinking I could do almost exactly the same thing. However when I select the drop down, I get no items. If I remove the ContainerStyle then that works a treat.

I've looked at the various examples in the help, but nothing seems to work.

Both these code examples fail:

<UserControl.Resources>
    <Style x:Key="ComboIsEnabledStyle" TargetType="{x:Type tel:RadComboBoxItem}">
        <Setter Property="IsEnabled" Value="{Binding ddDashEnabled}"/>
    </Style>
</UserControl.Resources>
 
<tel:RadComboBox
    x:Name="comboWindow2"
    SelectedValue="{Binding Window2Page}"
    ItemsSource="{Binding listDashData, UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="ddDashDescription"
    SelectedValuePath="ddDashName"
    ItemContainerStyle="{StaticResource ComboIsEnabledStyle}"
    SelectionChanged="comboWindow2_SelectionChanged">      
</tel:RadComboBox>
 
<tel:RadComboBox
    x:Name="comboWindow1"
    SelectedValue="{Binding Window1Page}"
    ItemsSource="{Binding listDashData, UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="ddDashDescription"
    SelectedValuePath="ddDashName"
    SelectionChanged="comboWindow1_SelectionChanged">
    <tel:RadComboBox.ItemContainerStyle>
        <Style TargetType="{x:Type tel:RadComboBoxItem}">
            <Setter Property="IsEnabled" Value="{Binding ddDashEnabled}"/>
        </Style>
    </tel:RadComboBox.ItemContainerStyle>
</tel:RadComboBox>

I amended one of the Telerik ComboBox examples to demonstrate as that does exactly the same thing. Can't attach, so it's available here: ComboBoxCustomFilteringDemo.zip

I'm really stumped as to what I've missed, as this should really be such a simple thing to do.

BTW I'm running the latest 2015.1.225 WPF version

6 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 14 Apr 2015, 09:57 AM
Hello Mike,

We tested both the provided sample project and the code-snippet with version 2015.1.225, but it seems everything works as expected on our side - the items get disabled. Please, check the attached sample project and let us know if didn't miss something. Is so, please modify it in order to reproduce the observed issue. Thus we could be able to continue our investigation and provide you with a prompt solution if possible. 

We are looking forward to hearing from you.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mike
Top achievements
Rank 1
answered on 15 Apr 2015, 11:56 PM

Hi

Thanks for the demo. This does indeed work fine. I've looked back at the demo I sent you and my main app and the only thing I can see different is that they use implicit themes. 

I've gone back over the guidance here: http://docs.telerik.com/devtools/wpf/styling-and-appearance/styling-apperance-implicit-styles-overview and applied this to the demo you attached. I have tried both methods of either including the xaml directly with the no-xaml dlls, or including the theme dll along with the no-binary dlls. In both instances I get the combo box failing to drop down properly. I've uploaded the demo you provided with the theme changes (here) and also a quick video of what I see on my side (here).

I must be doing something pretty fundamentally wrong when I add the theme I would think. 

This is the path to the XAML I import: C:\Program Files (x86)\Telerik\UI for WPF Q1 2015\Themes.Implicit\WPF40\VisualStudio2013\Themes

This is the ​path to the binaries I import: C:\Program Files (x86)\Telerik\UI for WPF Q1 2015\Binaries.NoXaml\WPF45

I also tried the WPF40 folder, as I wasn't 100% sure if using the WPF45 binaries with the WPF40 theme noxaml would work, but I get the same result.

Thanks, Mike...

0
Mike
Top achievements
Rank 1
answered on 16 Apr 2015, 10:37 AM

After looking at a few more examples and forum posts I saw what the problem was.

I've not included the "BasedOn="{StaticResource RadComboBoxItemStyle}"" as part of the style override. I've just added that in and it's now behaving as it should.

Thanks for the help.

0
Nasko
Telerik team
answered on 16 Apr 2015, 10:40 AM
Hello Mike,

I am glad that you've managed to achieve the desired appearance of RadComboBox. If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Jason
Top achievements
Rank 1
answered on 03 Mar 2017, 08:35 PM

Hello,

We are attempting to use the RadComboBox with "disabled" items as is outlined in this thread. Unfortunately, we are encountering a problem that is also present in the example posted above. Our problem is that if the user moves focus to the RadComboBox via tabbing (or any other mechanism that does not "open" the drop-down) the user can use the Up\Down buttons on the keyboard to change their selected item, when using the keyboard the "Disabled" items CAN be selected. We need the disabled items to be "skipped" when performing the keyboard selection. After opening the drop-down it appears the "item" IsEnabled binding fires and all subsequent keyboard functionality works correctly. Any guidance on how to resolve this issue would be greatly appreciated.

Thanks in advance!

Jason

0
Nasko
Telerik team
answered on 06 Mar 2017, 08:49 AM
Hello Jason,

You are absolutely right. Before the DropDown is opened the items are not yet initialized and because of that when using the keyboard they could be selected.

So, what we could suggest you is to handle the Loaded event of the ComboBox. Inside it to set the IsDropDownOpen property to True in order to open the DropDown of the control and initialize its items and to close it after that. Thus the disabled items should not be selected through the keyboard.

We have modified the sample in order to demonstrates the described above approach and you could run and evaluate it.

Hope this helps.

Regards,
Nasko
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ComboBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Mike
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Share this question
or