Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello,
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:
 
<base:ViewBase.Resources>
    <observable:DocTypeNames x:Key="DocTypesList" Value="{Binding TypeNamesList}"/>
</base:ViewBase.Resources>
 
Static resource bounded to List in ViewModel (working fine - can be bounded to any control)
 
<wfcGrid:WFGridViewDataColumn Width="200" IsSortable="True" DataMemberBinding="{Binding CategoryName}">
    <wfcGrid:WFGridViewDataColumn.Header>
        <TextBlock TextWrapping="Wrap" Text="Kategoria dokumentu"/>
    </wfcGrid:WFGridViewDataColumn.Header>
    <wfcGrid:WFGridViewDataColumn.FilteringControl>
        <filters:ListSelectionFilter NamesList="{Binding Value,Source={StaticResource DocTypesList}}"/>
    </wfcGrid:WFGridViewDataColumn.FilteringControl>
    <wfcGrid:WFGridViewDataColumn.CellTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Margin="5" TextWrapping="Wrap" Text="{Binding CategoryName}"/>
            </StackPanel>
        </DataTemplate>
    </wfcGrid:WFGridViewDataColumn.CellTemplate>
</wfcGrid:WFGridViewDataColumn>
This is a part of GridView template thats why i cannot bind TypeNamesList directly.
 
The property in ListSelectionFilter control
public List<string> NamesList
{
    get
    {
        return (List<string>)GetValue(NamesListProperty);
    }
    set
    {
        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
<base:ViewBase.Resources>
<sys:String x:Key="Name">Nazwa</sys:String>       
</base:ViewBase.Resources>
When im using something like:
<wfcGrid:WFGridViewDataColumn.FilteringControl>
                                                    <filters:FromDateToDateFilterControl Name="{StaticResource Name}"/>
                                                </wfcGrid:WFGridViewDataColumn.FilteringControl>
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.
Posted 14-Jul-10 5:41am

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 504
1 Maciej Los 349
2 Kornfeld Eliyahu Peter 325
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 14 Jul 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100