Hello
I have a Silverlight application in which I am using the RadDataFilter. This RadDataFilter uses a list of custom objects as the data source for the testComboBox. When a user clicks the "Test" button, the filter value is always set to "Unset". For instance, if I use the code below, I always see "Priority IsEqualTo <Unset>". However, if I use use a List of string values, everything works fine. Here is my code:
Finally, here is the Template selector code:
How do I use a Custom type for the filter options in a Editor Template?
Thank you!
I have a Silverlight application in which I am using the RadDataFilter. This RadDataFilter uses a list of custom objects as the data source for the testComboBox. When a user clicks the "Test" button, the filter value is always set to "Unset". For instance, if I use the code below, I always see "Priority IsEqualTo <Unset>". However, if I use use a List of string values, everything works fine. Here is my code:
<
UserControl.Resources
>
<
DataTemplate
x:Key
=
"priorityTemplate"
>
<
telerik:RadComboBox
x:Name
=
"testComboBox"
MinWidth
=
"100"
DisplayMemberPath
=
"Title"
SelectedValue
=
"{Binding Path=Value, Mode=TwoWay, FallbackValue=null}"
SelectionChanged
=
"testComboBox_SelectionChanged"
>
<
telerik:RadComboBox.ItemsPanel
>
<
ItemsPanelTemplate
>
<
VirtualizingStackPanel
MinWidth
=
"320"
/>
</
ItemsPanelTemplate
>
</
telerik:RadComboBox.ItemsPanel
>
</
telerik:RadComboBox
>
</
DataTemplate
>
<
DataTemplate
x:Key
=
"locationTemplate"
></
DataTemplate
>
<
DataTemplate
x:Key
=
"typeTemplate"
></
DataTemplate
>
<
code:MyEditorTemplateSelector
x:Key
=
"myEditorTemplate"
>
<
code:MyEditorTemplateSelector.EditorTemplateRules
>
<
code:MyEditorTemplateRule
PropertyName
=
"Priority"
DataTemplate
=
"{StaticResource priorityTemplate}"
/>
<
code:MyEditorTemplateRule
PropertyName
=
"Location"
DataTemplate
=
"{StaticResource locationTemplate}"
/>
<
code:MyEditorTemplateRule
PropertyName
=
"TypeName"
DataTemplate
=
"{StaticResource typeTemplate}"
/>
</
code:MyEditorTemplateSelector.EditorTemplateRules
>
</
code:MyEditorTemplateSelector
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
Button
Content
=
"Test"
Height
=
"30"
Width
=
"90"
Margin
=
"0,0,0,8"
HorizontalAlignment
=
"Left"
Click
=
"Button_Click"
/>
<
telerik:RadDataFilter
x:Name
=
"filter"
Grid.Row
=
"1"
EditorCreated
=
"filter_EditorCreated"
AutoGenerateItemPropertyDefinitions
=
"False"
EditorTemplateSelector
=
"{StaticResource myEditorTemplate}"
Loaded
=
"filter_Loaded"
/>
</
Grid
>
Here is the relevant parts of the my code-behind:
Here is the definition for Priority.cs:private void filter_Loaded(object sender, RoutedEventArgs e)
{
ItemPropertyDefinition priorityDefinition = new ItemPropertyDefinition("Priority", typeof(string), "Priority");
filter.ItemPropertyDefinitions.Add(priorityDefinition);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string rules = string.Empty;
foreach (FilterDescriptor description in filter.FilterDescriptors)
rules += description.ToString() + "\n";
MessageBox.Show(rules);
}
private void filter_EditorCreated(object sender, EditorCreatedEventArgs e)
{
switch (e.ItemPropertyDefinition.PropertyName)
{
case "Priority":
// This works
List<
string
> options = new List<
string
>() { "High", "Low" };
//(RadComboBox)(e.Editor)).ItemsSource = options;
// This doesn't
List<
Priority
> priorities = new List<
Priority
>();
priorities.Add(new Priority("High", true));
priorities.Add(new Priority("Low", false));
((RadComboBox)(e.Editor)).ItemsSource = priorities;
break;
}
}
public class Priority
{
public string Title { get; set; }
public bool Val { get; set; }
public Priority(string title, bool val)
{
this.Title = title;
this.Val = val;
}
}
Finally, here is the Template selector code:
public class MyEditorTemplateSelector : DataTemplateSelector
{
private List<
MyEditorTemplateRule
> templateRules = new List<
MyEditorTemplateRule
>();
public List<
MyEditorTemplateRule
> EditorTemplateRules
{
get { return templateRules; }
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
ItemPropertyDefinition propertyDefinition = (ItemPropertyDefinition)item;
foreach (MyEditorTemplateRule rule in templateRules)
{
// Select the appropriate template for each property.
if (rule.PropertyName == propertyDefinition.PropertyName)
{
return rule.DataTemplate;
}
}
return base.SelectTemplate(item, container);
}
}
public class MyEditorTemplateRule
{
private string propertyName;
public string PropertyName
{
get
{
return this.propertyName;
}
set
{
this.propertyName = value;
}
}
private DataTemplate dataTemplate;
public DataTemplate DataTemplate
{
get
{
return this.dataTemplate;
}
set
{
this.dataTemplate = value;
}
}
}
How do I use a Custom type for the filter options in a Editor Template?
Thank you!