Why the need for binding in this context

I am starting WPF looking at How to do o: Getting started with Entity Framework

I'm confused why I need

<ListBox Name="ListBox1" ItemsSource="{Binding Source={StaticResource CustomerSource}}" >

why can't i

<ListBox Name="ListBox1" ItemsSource="{StaticResource CustomerSource}" >

how to find out when i need to Binding. because on the 1st thought, just like I use a static resource in styles

<Button Style="{StaticResource someStyle}"

why not

<Button Style="{Binding Source={StaticResource someStyle}}"
+3
source share
2 answers

This example assigns a value obtained from resources using the specified key to the Text property:

<TextBox Text="{StaticResource SomeText}" />

In the examples, the Text property is bound to the property of an object extracted from resources using the specified key:

<TextBox Text="{Binding Source={StaticResource SomeObject}, Path=SomeProperty}" />

, , , . .

, , . :

  • UI
  • /

:

+2

DataContext . ListBox , , StackPanel.

<StackPanel x:Name="parentControl" DatContext="{StaticResource CustomerSource}">
<ListBox x:Name="ListBox1" ItemSource="{Binding}">
...
</ListBox>
</StackPanel>
0

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


All Articles