上一節,提到了控制空值的targetnullvalue。本節介紹下另外兩個跟繫結有關的關鍵字:stringformat,fallbackvalue。
stringformat,顧名思義就是格式化字串,在資料繫結的過程中,這個當然很重要了,誰不愛美阿。先看看上節的例子:
<為了很好的顯示我們所需要的資料,用了三個textblock,顯得很囉嗦有很吃力,那麼有沒有更好的方法呢,用multibinding和stringformat。window x:class="
wpfproject.test
"xmlns="
"xmlns:x="
"title="
test
"height="
300"
width="
300"
loaded="
window_loaded
">
<
grid
>
<
listbox name="
lbxpersons
">
<
listbox.itemtemplate
>
<
datatemplate
>
<
stackpanel orientation="
horizontal
">
<
textblock text="
"width="
50"/>
<
textblock text="
"width="
50"/>
<
textblock text="
"/>
stackpanel
>
datatemplate
>
listbox.itemtemplate
>
listbox
>
grid
>
window
>
fallbackvalue設定邦定不存在時顯示的資訊。還是上面的例子,person類裡不存在birthday屬性,我們在繫結裡新增,讓它顯示不存在。
**
<執行:window x:class="
wpfproject.test
"xmlns="
"xmlns:x="
"title="
test
"height="
300"
width="
300"
loaded="
window_loaded
">
<
grid
>
<
listbox name="
lbxpersons
">
<
listbox.itemtemplate
>
<
datatemplate
>
<
textblock
>
<
textblock.text
>
<
multibinding stringformat="
{}-,,
">
<
binding path="
firstname
"/>
<
binding path="
lastname
"/>
<
binding path="
age"
targetnullvalue='
age unknown
'/>
<
binding path="
birthday
"fallbackvalue='
birthday unknown
'/>
multibinding
>
textblock.text
>
textblock
>
datatemplate
>
listbox.itemtemplate
>
listbox
>
grid
>
window
>

ok。
輸入輸出命令的邦定過程及資料傳送
一 ep的註冊 二 關於輸入輸出命令的邦定過程 以 為例 三 關於輸入命令邦定後資料的傳送 1 傳送引數中afaddrtype t dstaddr如下 dstaddr.addrmode afaddrnotpresent dstaddr.endpoint 註冊的ep號 dstaddr.addr.sho...
輸入輸出命令的邦定過程及資料傳送
輸入輸出命令的邦定過程及資料傳送 一 ep的註冊 二 關於輸入輸出命令的邦定過程 以 為例 三 關於輸入命令邦定後資料的傳送 1 傳送引數中afaddrtype t dstaddr如下 dstaddr.addrmode afaddrnotpresent dstaddr.endpoint 註冊的ep號...
WPF資料繫結(二)
前面講了最近本的兩種資料繫結,這次講講資源繫結和context繫結 1 資源繫結 同樣不需要寫 僅僅需要配置xaml就可以了。1 tabitem header resourcebinding 2 stackpanel 3 stackpanel.resources 4 sys string x key...