簡體   English   中英

綁定觸發更新

[英]Trigger updates with binding

試圖找出一種使列表框顯示當前值的快速方法,如下所示:

listbox is bound to a ObservableCollection<TypeA>

和TypeA.ToString()返回TypeA.Name

並在列表框中選擇一個項目,將在某些文本框中顯示TypeA字段以進行編輯

更新TypeA.Name不會更新列表框中顯示的值嗎?

如何通知列表框獲取當前值?

在文本框中更改值時更新列表框會更好!

謝謝

您可以在列表框和文本框之間進行元素綁定。

<TextBox Name="txtName"/>
<ListBoxItem SelectedItem = "{Binding ElementName=txtName, Path=Text}"/>

您可以通過將文本框綁定到列表框中的選定項目來執行此操作,如下所示:

<ListBox Name="listBox">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Name}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>


<TextBox Name="tbName" Text="{Binding ElementName=listBox, Path=SelectedItem.Name, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Name="tbField2" Text="{Binding ElementName=listBox, Path=SelectedItem.Field2, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Name="tbField3" Text="{Binding ElementName=listBox, Path=SelectedItem.Field3, UpdateSourceTrigger=PropertyChanged}" />

當您更改文本框中的文本時,列表框中的所選項目將更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM