2010-07-09 2 views
0

Я stuggeling с привязкой данных с в пользовательском элементе управленияпользовательского управления привязкой к коллекции в собственности

У меня есть некоторые свойства в моем настраиваемом элементе управления.

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); 
    } 

} 

Связывание с таблицей не представляет проблемы. это отлично работает

, но теперь я хочу привязываться к свойству ключевого слова в пределах pageDictionary.

public class PageDictionary 
{ 
    //some other properties.... 
    public List<string> Keywords 
    { 
     get 
     { 
      return GetKeyWords(); 
     } 
    } 
} 

Это файл XAML.

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:InnaxBook" > 
    <Style x:Key="alternatingWithTriggers" 
       TargetType="{x:Type ContentPresenter}"> 
     <Setter Property="Height" Value="25"></Setter> 
    </Style> 
    <DataTemplate x:Key="HelpTopicLineTemplate"> 
     <Border x:Name="HelpTopicLine"> 
      <StackPanel Orientation="Horizontal"> 
       <Button Content="{Binding DictionaryName}" Width="25px" x:Name="btnGoto" ></Button> 
      </StackPanel> 
     </Border> 
    </DataTemplate> 
    <Style TargetType="{x:Type local:Manual}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:Manual}" > 
        <Border Background="{TemplateBinding Background}" 
          BorderBrush="{TemplateBinding BorderBrush}" 
          BorderThickness="{TemplateBinding BorderThickness}"> 
         <Grid> 
          <Grid Height="Auto" Width="Auto"> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="125" /> 
            <ColumnDefinition Width="*" /> 
           </Grid.ColumnDefinitions> 
           <Grid.RowDefinitions> 
            <RowDefinition Height="30" /> 
            <RowDefinition Height="*" /> 
            <RowDefinition Height="30" /> 
           </Grid.RowDefinitions > 
           <Label x:Name="TitleControl" Content="{TemplateBinding Title }" Grid.ColumnSpan="2" Grid.Column="0" Grid.Row="0" Background="Aqua" ></Label> 
           <StackPanel x:Name="IndexContainer" Grid.Column="0" Grid.Row="1" Height="Auto" Width="Auto" Orientation="Vertical" ScrollViewer.CanContentScroll="True"> 
            <Label Height="30" Margin="0,0,0,0" HorizontalAlignment="Left" Content="{TemplateBinding IndexLabelText}" /> 
            <ListView HorizontalAlignment="Stretch"> 
             <Button Height="Auto" HorizontalContentAlignment="Stretch" Content="knoppie" /> 
            </ListView> 

            <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> 
</ResourceDictionary> 

если кто-то может помочь мне с этим ...

ответ

0

В вашем случае класс PageDirectory необходимо реализовать INotifyPropertyChanged интерфейс. Каждый раз, когда ключевое слово внутри изменилось вам нужно поднять событие PropertyChanged так:

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

Связывающая строка, то будет иметь вид, как это:

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

Где локальный это пространство имена объявлены верхние в XAML для доступ к типу PageDictionary.

Смежные вопросы