2010-07-09 3 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 인터페이스를 구현해야합니다. 바인딩 문자열을 다음과 같이 볼 수있을 것이다

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

: 키워드가 내부 변경 때마다이 같은하여 PropertyChanged 이벤트를 발생해야하는 네임 스페이스의 XAML에서 상위 선언 된 지역

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

PageDictionary 유형에 액세스하십시오.

관련 문제