Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1320
Filtering Items in XamComboEditor Conditionally
posted

Hi all,

 

I need to design a custom control based on the XamComboEditor which is capable of filtering the contained items in the following manner:

The control holds objects of type:

 

public class CodeData

 {

public string Code { get; set; }

public string DisplayableLabel { get; set; }

public DateTime? ExpirationDate { get; set; }

public override string ToString()

 {

     return DisplayableLabel;

 }

 }

 

The value "code" is what interests me, however the control needs to display "displayableLabel".

The control needs to hold an exclusion list containing elements ("Code") that should never be displayed.

When a user opens the dropdown only those codes that are present in a databound collection minus the codes in the exclusion list should be displayed.

In code, however, it needs to be possible to assign a code that exists in the databound collection, regardless whether it is present in the exclusion list. When assigning in code it should appear as the selected item, and should be shown in the comboEditor, but not should not appear in the dropdown list. In this way, a user cannot set the ComboEditor to an excluded item, but in code, it can be.

 

As a small experiment, I wrote the following XAML. Here I try to have only the elements show that start with "a". This does not appear to work.

 

<ig:XamComboEditor x:Name="Cbx" AutoComplete="False" AllowFiltering="True" DisplayMemberPath="DisplayableLabel">

<ig:XamComboEditor.CustomItemsFilter>

<ig:ItemsFilter>

<ig:ItemsFilter.Conditions>

<ig:ComparisonCondition Operator="StartsWith" FilterValue="a"/>

</ig:ItemsFilter.Conditions> 

</ig:ItemsFilter>

</ig:XamComboEditor.CustomItemsFilter>

</ig:XamComboEditor>

 

Code behind:

public InfrComboBoxCode()

{

InitializeComponent();

var code = new CodeData { Code = "aTEST", DisplayableLabel = "aTest code", ExpirationDate = null };

 _collection.Add(code);    

var code2 = new CodeData { Code = "bTEST2", DisplayableLabel = "bTest code2", ExpirationDate = null };

_collection.Add(code2);

var code3 = new CodeData { Code = "cTEST3", DisplayableLabel = "cTest code3", ExpirationDate = null };

 _collection.Add(code3);

 Cbx.ItemsSource = _collection;

}

 

What am I doing wrong? How should I implement the more complex filter criterium that abides by the exclusion list?

I've tried implementing my own IFilterCondition, but I have no clue on what the methods should be doing.

 

Many Thanks,