0

次のようなものを実現したいと思います(Window要素のDataContextプロパティに注意してください)。

<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
4

1 に答える 1

1
<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>

DependencyProperty を使用する方が良いと思います。うまく同期する必要があります。

于 2009-09-30T02:36:13.747 に答える