2013-02-27 84 views
0

我有一個Windows Phone應用程序一個StackPanel有三個TextBlock S,在頁面上,看起來有些事情是這樣的:顯示控制

<StackPanel> 
    <TextBlock></TextBlock> 
    <TextBlock></TextBlock> 
    <TextBlock></TextBlock> 
</StackPanel> 

基於屬性值,我想顯示TextBlock中的任何一個。假設如果我有一個名爲「Name」的屬性,並且如果此屬性的值爲「1」,我想只顯示類似於第2和第3個的第一個TextBlock。有誰知道我該如何完成此任務?

+0

是有可能有一個文本塊,然後更改文本和位置?編輯︰否則一個switch語句取決於propertycontent,如果它始終是一個數字 – Sayse 2013-02-27 09:36:39

+0

否我不能改變可能是我可以有不同的控制..所以我不能改變文本和位置 – 2013-02-27 09:38:11

+0

你可以請解釋2和3的情況,因爲它不是從1清除。 – Anobik 2013-02-27 11:54:23

回答

0

綁定的可見性,以你的模型的屬性和使用轉換器: http://windowsphonegeek.com/articles/talking-about-converters-in-wp7--coding4fun-toolkit-converters-in-depth

public class IntToVisibilityConverter : IValueConverter 
    { 

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    int intValue (int)value; 

    if(intValue == 1) 
return Visibility.Visible; 
else 
return Visibility.Collapsed; 
} 

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
throw new NotImplementedException(); 
} 

}

+0

謝謝你的答案。如果我有10個文本塊,如果我想顯示2,如果屬性內容是「 5「然後我想我不能使用這個... – 2013-02-27 09:42:57