【发布时间】:2014-04-03 13:45:44
【问题描述】:
我想将列表框项的 DataBinding 链接到新窗口
“名称”按钮应打开一个带有列表框项的 DataBinding 的新窗口。
绑定是一个 .xml 文件:
<People>
<Person image="Test.jpg" company="" position="" website="" chat="" notes="">
<Name first_name="Max" second_name="" last_name="Mustermann" salutation="" />
<Email email1="" email2="" email3="" />
<Phone_Numbers business="" private="" mobile="" />
<Business_Adress street="" place="" state="" postalcode="" country="" />
<Private_Adress street="" place="" state="" postalcode="" country="" />
</Person>
</People>
并且新窗口应该链接到 Person 的 Name 元素。
虽然会有不止一个人,但窗口应该链接到正确的人。
这是 XmlDataProvider:
<XmlDataProvider x:Name="XmlData" Source="People.xml" XPath="/People/Person" />
列表框的绑定如下:
<ListBox
Grid.Row="0"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding UpdateSourceTrigger=Explicit}"
x:Name="PeopleListBox"
SelectionMode="Single">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1} {2}">
<Binding XPath="Name/@last_name" />
<Binding XPath="Name/@first_name" />
<Binding XPath="Name/@second_name" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
【问题讨论】:
-
你有什么问题?
-
我该怎么做,因为它只打开第一个人
-
请显示一些代码。
-
我添加了一些代码
标签: c# wpf data-binding listbox