2010-05-19 2 views
0

C# 및 Silverlight의 GIS 웹 사이트에서 작업 중이며 맵 레이어를 기반으로 ListBox를 채우려고합니다. 이 코드는 모든 파일을 단일 XAML 파일 (동일한 파일에서 Map이 정의 된 위치)에 모두 모아 두었습니다.하지만 별도의 클래스로 분리하려고 시도하고 ListBox가 다른 클래스에 채워지지 않습니다.XAML ListBox Binding

XAML 코드 ..

  <CheckBox IsChecked="{Binding Visible, Mode=TwoWay}" /> 

      <Slider Margin="-5,0,0,0" Minimum="0" Maximum="1" Width="30" 
       Value="{Binding Opacity, Mode=TwoWay}" Height="18" />--> 

      <TextBlock Text="{Binding ID, Mode=OneWay}" Margin="5,0,0,0" > 

      <ToolTipService.ToolTip> 
       <StackPanel MaxWidth="400"> 
        <TextBlock FontWeight="Bold" Text="{Binding CopyrightText}" TextWrapping="Wrap" /> 
        <TextBlock Text="{Binding Description}" TextWrapping="Wrap" /> 
       </StackPanel> 
      </ToolTipService.ToolTip> 
      </TextBlock> 
     </StackPanel> 
    </DataTemplate> 

클래스이 C# 코드에 의해 호출 될 때

에는 myMap 설정되고 ...

공용 부분 클래스 TableOfContents : UserControl { 지도 myMap;

public TableOfContents(ref Map map) 
{ 
    InitializeComponent(); 

    myMap = map; 

    foreach (Layer thisLayer in myMap.Layers) 
    { 
     layerList.Items.Add(new TextBlock() { Text = thisLayer.ID }); 
    } 
} 

}

foreach는 문 (이것은 단지 테스트 코드)지도 레이어의 모든 TextBlocks을 추가, 그래서 '나는 정보가 제대로 전달되는 알고 있지만, 데이터가 XAML에 정의 된 바인딩 아무튼 작동하지 않는 것 같습니다.

의견이 있으십니까?

편집 : XAML 코드가 게시물에 잘린 것처럼 보입니다 (편집 할 때 표시됨). 데이터에 의해 정의 된 바인딩 :. 는 ItemsSource = "{경로 = 레이어를 결합하면, ElementName을 =에는 myMap}

답변

0

이 탄 부여 - ItemsSource ="{바인딩 myMap.Layers을} "

어쩌면 간단한 옵션은 것 "this.DataContext = map"을 생성자에 설정하면 Binding은 다음과 같이 보입니다 : ItemsSource = "{Binding Layers}"myMap을 완전히 제거 할 수 있습니다 ..