第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從選定的 ListBoxItem 模板中獲取 Textblock 值

從選定的 ListBoxItem 模板中獲取 Textblock 值

C#
皈依舞 2021-10-31 19:15:19
有人知道如何從運行時生成的列表框項中提取文本塊文本嗎?我有一個自定義的 ListBoxItem,其中包含一個 SymbolIcon 和一個 textBlock。我只需要 textBlock 值。private void AlbumSongList_SelectionChanged(object sender, SelectionChangedEventArgs e)    {        var selected = AlbumSongList.SelectedItem as ListBoxItem;        DataTemplate template = selected.ContentTemplate;        Debug.WriteLine("You have selected the song: " + selected.ToString());    }這是包含文本塊的自定義控件同樣,如果您看到具有 Sing 文本綁定源的“Textblock”,這就是我需要的文本值。
查看完整描述

1 回答

?
慕雪6442864

TA貢獻1812條經(jīng)驗 獲得超5個贊

ListBox具有默認(rèn)選擇行為,該行為取決于項目源是什么(用于 的類型ItemsSource)。所以 theSelectedItem是你的Model類的類型,所以你可以TextBlock從你選擇的模型中獲取 的文本。


例如,您的模型類 Name 是Model,那么您可以使用以下代碼獲取文本,


private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

    var selected = AlbumSongList.SelectedItem as Model;


    Debug.WriteLine("You have selected the song: Song Number is {0}, and Song is {1}",

        selected.SongNumber, selected.Song);

}


查看完整回答
反對 回復(fù) 2021-10-31
  • 1 回答
  • 0 關(guān)注
  • 309 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號