0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Visual Studio / WPF > binding > Path=CompanyList/WebSiteとしてのバインディング例

Last updated at Posted at 2017-06-05
動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

http://gushwell.ldblog.jp/archives/52305764.html
を元に学習中。

気になったコード部分。

<TextBlock HorizontalAlignment="Stretch" Height="27" Margin="10,5"
15
                   TextWrapping="Wrap" VerticalAlignment="Top"
16
                   Text="{Binding Path=CompanyList/WebSite}"  />

この時に、TextプロパティのBinding指定は、以下のように書きます。

   Text="{Binding Path=CompanyList/WebSite}"

プロパティ名をスラッシュで区切って記述することで、階層的なデータ構造にアクセスすることが できます。

かずきさんのblogでも同様の表記を見つけた。
http://blog.okazuki.jp/entry/2014/10/29/220236

この”/”を使ったバインディングは、親子だけでなく孫やその先までコレクションがある限り指定できます。例えば、Peopleコレクションの選択中の項目のChildrenプロパティ(これもコレクション)の選択中の項目のNameプロパティは“People/Children/Name”のように指定できます。

...

選択項目をバインドするためにPeople/NameのようにPathを指定してデータバインディングを行います。

<!-- 現在選択中の項目をバインドする -->
<Label Content="名前"/>
<TextBox TextWrapping="Wrap" Text="{Binding People/Name}"/>
<Label Content="年齢"/>
<TextBox TextWrapping="Wrap" Text="{Binding People/Age}"/>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?