views:

12

answers:

1

HI,

I stuggeling with the databinding with in a custom control

I've got some properties within my custom control.

    public static DependencyProperty TitleProperty;
    public static DependencyProperty PageDictionaryProperty;

    public string Title
    {
        get
        {
            return (string)base.GetValue(TitleProperty);
        }
        set
        {
            base.SetValue(TitleProperty, value);

        }

    }
    }

    public Innax.ManualParts.PageDictionary PageDictionary
    {
        get
        {
            return (Innax.ManualParts.PageDictionary)base.GetValue(PageDictionaryProperty);
        }
        set
        {
            base.SetValue(PageDictionaryProperty, value);
        }

    }

binding to teh table isn't a problem. this works fine

but now i want to bind to the keyword property within the pageDictionary.

public class PageDictionary {

//some other properties....

    public List<string> Keywords
    {
        get
        {
            return GetKeyWords();
        }
    }

}

This is the XAML file.

                                <ItemsControl ItemContainerStyle="{StaticResource alternatingWithTriggers}" 
                                        AlternationCount="2" 
                                        x:Name="RelatedItemsControl" 
                                        Grid.Row="1"
                                        Grid.Column="0"
                                        ItemsSource="{TemplateBinding PageDictionary}"
                                        ItemTemplate="{StaticResource HelpTopicLineTemplate}">
                                </ItemsControl>

                            </StackPanel>
                        </Grid>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

</Style>

if anyone could help me with this...

kind regards,

Frans

A: 

In your case the PageDirectory class need to implement INotifyPropertyChanged interface. Each time the keyword inside changed you need to raise a PropertyChanged event like this:

if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Keywords"))

The binding string then will have view like this:

{Binding Keywords, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PageDictionary}}}

Where local is namespace declared upper in the xaml for access PageDictionary type.

Eugene Cheverda