WPF 控制項如何繫結資源中的資料

2021-06-21 22:17:33 字數 662 閱讀 3631

關於在xaml中的控制項如何繫結資源中的資料

xmlns=""

xmlns:x=""

xmlns:sys="clr-namespace:system;assembly=mscorlib" >abcd

3.14159

c# **:

string txtsong = (string)this.findresource("msong");

this.txtword.text = txtsong;

double txtratio = (double)this.findresource("cirratio");

this.txtcirratio.text = txtratio.tostring();

執行結果:

abcd

abcd

3.141590

3.1415

abcd

3.14159

------------------------

因為textblock的text是string,所以要通過stringfromat來轉換格式

c  將字串轉換為美元格式

e  科學記數法

p  轉換為百分比

f  f後邊的數字決定保留幾位小數

wpf 中Listbox控制項的資料繫結顯示

listbox的資料繫結顯示的步驟 首先在程式檔案上右擊,新建乙個類檔案 如lst1.cs 類中定義屬性。回到窗體介面,手動編寫或拖乙個listbox控制項。在後台程式的窗體載入事件中,新建類的引用物件。然後定義乙個泛型集合list 類名 list new list 類名 對類的屬性進行賦值操作。使...

WPF常用資料繫結控制項集合

1 怎麼用listview控制項把xml中的資料在介面上顯示出來?1.0 encoding utf 8 yellow 男血性 女 溫柔 containercontrol.mainwindow xmlns xmlns x title mainwindow height 350 width 525 hu...

WPF常用資料繫結控制項集合

1 怎麼用listview控制項把xml中的資料在介面上顯示出來?1.0 encoding utf 8 yellow 男血性 女 溫柔 containercontrol.mainwindow xmlns xmlns x title mainwindow height 350 width 525 hu...