0
模板化控件我正在使用ValueConverter像這樣:參數化ControlTemplate中使用的ValueConverter的好方法是什麼?
<ListBox>
<ListBox.Resources>
<Controls:CodeDescriptionValueConverter x:Key="CodeDescriptionValueConverter"/>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource CodeDescriptionValueConverter}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
這是我在generic.xaml提供默認的樣子。當我使用這個控件時,我想要將不同的格式字符串傳遞給轉換器。如果沒有提供完整的ControlTemplate,是否有辦法實現這一點?
我首先想到的是,我可以用ConverterParameter與TemplateBinding到屬性上的控制,但我發現,ConverterParameters不能綁定到。另一種選擇是從ConvertTo方法訪問控件,然後選取該屬性。我不知道該怎麼做。任何可以消除每次使用時都完全重新設計控件模板的選項將會很有幫助(這是很多Xaml)。
感謝您的反饋火PropertyChanged事件的格式化文本屬性,這些都是我hadn一些好的可能性」沒想到。 – 2009-09-09 20:02:06