How to set itemsource?

This dialogue makes no sense to me

http://img576.imageshack.us/img576/4223/50709706.gif

And I have problems finding good study guides. Most examples are not detailed enough or are done using code, but I would like to use the IDE as much as possible.

What is the difference between ItemsSourceand DataContext?

I would like to link it to a starter-only list. I don't need SQL or databases or anything interesting. Where can I announce my list? In MainWindow.xaml.cs? How to make it appear in this dialog box?

+3
source share
3 answers

"DataContext" "" .

, , ( TextBox ):

<TextBox Text="{Binding Path=Foo,Source={StaticResource Bar}}" />

, TextBox.Text Foo , Bar ( - ).

, , Bar, Bar DataContext . DataContext , DataContext . :

<StackPanel DataContext="{StaticResource Bar}">
    <TextBox Text="{Binding Path=Foo}" />
    <TextBox Text="{Binding Path=Fizz}" />
    <TextBox Text="{Binding Path=Buzz}" />
</StackPanel>

- , , .

, . "" ItemsSource. "DataContext", Visual Studio, ItemsControl - DataContext (, ).

(ElementName, RelativeSource StaticResource), ItemsControl.

, DataContext, "" , . , (, ListBox):

<ListBox ItemsSource="{Binding Path=Foos}" />

, ListBox "Foos", , DataContext - (, ).

+5

. DataContext (DataContext = this;) UserControl code-behind, UserControl .

ListBox, ItemsSource , - .

+1

This is a pretty good walkthrough: http://windowsclient.net/learn/video.aspx?v=315275

In particular, you need to install first DataContextto indicate where to look ItemsSource. The easiest way is to install this in a window via XAML:

<Window.DataContext>
    <controllers:DownloadManager />
</Window.DataContext>
+1
source

Source: https://habr.com/ru/post/1744253/


All Articles