Click here to Skip to main content
14,733,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
A bit larger question this time but i hope it's only alot of code and the solution is short, simple and easy and the problem is only becouse of my temporary impairment.

I need to create ItemsSource to my CustomControl. The problem is the control is using to filter records in grid view so in MVVM pattern i need some databindings with various DataContexts.
Here are main parts of code:

View with GridView bounded to certain source:

    <observable:DocTypeNames x:Key="DocTypesList" Value="{Binding TypeNamesList}"/>

Static resource bounded to List in ViewModel (working fine - can be bounded to any control)

<wfcGrid:WFGridViewDataColumn Width="200" IsSortable="True" DataMemberBinding="{Binding CategoryName}">
        <TextBlock TextWrapping="Wrap" Text="Kategoria dokumentu"/>
        <filters:ListSelectionFilter NamesList="{Binding Value,Source={StaticResource DocTypesList}}"/>
                <TextBlock Margin="5" TextWrapping="Wrap" Text="{Binding CategoryName}"/>

This is a part of GridView template thats why i cannot bind TypeNamesList directly.

The property in ListSelectionFilter control
public List<string> NamesList
        return (List<string>)GetValue(NamesListProperty);
        if (itemsList == null)
            itemsList = new List<ListItem>();
        foreach (string s in value)
            if (s != null)
                itemsList.Add(new ListItem()
                    Name = s,
                    Value = false,
        SetValue(NamesListProperty, value);
        listBox.ItemsSource = itemsList;

public static readonly DependencyProperty NamesListProperty =
    DependencyProperty.Register(&quot;NamesList&quot;, typeof(List&lt;string&gt;), typeof(ListSelectionFilter), new PropertyMetadata(new List&lt;string&gt;()));

And ObservableObject used as static resource.
public class DocTypeNames : ObservableObject<IEnumerable<string>>

What i know so far is:
- The only thing working iside the template is basic type declared in
<sys:String x:Key="Name">Nazwa</sys:String>       

When im using something like:
                                                    <filters:FromDateToDateFilterControl Name="{StaticResource Name}"/>

Problem is when i'm using "Binding" expression.

- Enumerable Types/Interfaces doesn't matter. Or maybe i didn't found right one.

- Static resource with ObervableObject works fine with other Contexts when im binding for example:
<ComboBox x:Name="docTypeCombo" HorizontalAlignment="Left" Width="150" SelectedValuePath="Tree"

                      DisplayMemberPath="Name" SelectedValue="{Binding Path=DocumentType,Mode=TwoWay}" ItemsSource="{Binding Value,Source={StaticResource DocTypesList}}"


Combo box is inside DataForm with other DataContext but not in template. When i'm putting ComboBox inside DataForm.EditTemplate - its also working.

In my opinion the thing i'm doing wrong is declaration of ItemsSorce in custom control. Any tutorial i found shows that way but with source bound directly from ViewModel.

I'll be greatfull for any hint how to solve this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900