views:

321

answers:

1

I want to achieve something like the following (Notice the DataContext property of the Window element):

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="{Binding MyDataContext}"/>

Class Window1 
    Public ReadOnly Property MyDataContext() As IEnumerable(Of String)
        Get
            Return New String() {"Item1", "Item2"}
        End Get
    End Property
End Class
A: 
<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="{Binding MyDataContext, RelativeSource={RelativeSource Self}}">
    <Grid>
        <ListBox ItemsSource="{Binding}"/>
    </Grid>
</Window>

I think it might be better to use a DependencyProperty, it should synchronize well.

Shimmy