I'm working on a GIS website in C# and Silverlight, and I'm trying to populate a ListBox based on map layers. The code works if I lump everything together in a single XAML file (where the Map is defined in the same file), but I am trying to separate things into separate classes, and the ListBox will not populate in the other class.
XAML Code..
<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>
myMap is being set when the class is called by this C# code...
public partial class TableOfContents : UserControl { Map myMap;
public TableOfContents(ref Map map)
{
InitializeComponent();
myMap = map;
foreach (Layer thisLayer in myMap.Layers)
{
layerList.Items.Add(new TextBlock() { Text = thisLayer.ID });
}
}
}
The foreach statement adds TextBlocks for all of the map layers (this is just test code), so I know the information is being passed correctly, but the data binding defined in XAML doesn't seem to work.
Any thoughts?
EDIT: The XAML Code seems to be clipped in the post (although it's visible when I edit it). The data binding is defined by: ItemsSource="{Binding Path=Layers, ElementName=myMap}