我正在關注this answer on how to databind enums (ints in my case) to RadioButtons,但是如果我有幾個TabItem,每個都有10x10個RadioButton網格,有什麼方法可以去掉一些樣板?由於是,每個單選按鈕必須有與它所有這些信息:如何減少RadioButton綁定代碼?
<RadioButton
IsChecked="{Binding
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}},
Path=FavoriteColor,
Converter={StaticResource IntToBoolConverter},
Mode=TwoWay,
ConverterParameter=5}"
Content="Red" Grid.Column="4" Grid.Row="6" />
最好,我想能夠在TabControl的每一次設置的RelativeSource,轉換器和模式一次,路徑TabItem,並且每個RadioButton只設置ConverterParameter。這在XAML中可能嗎?如果不是,那麼在代碼隱藏方面做更有意義?
相關:HTTP:/ /stackoverflow.com/questions/6258505/(我的答案使用'ItemsControl'可能會有所幫助,您可以使用'UniformGrid'作爲面板)。 – 2012-02-04 23:41:52
@ H.B。哦,這意味着我不僅能夠擺脫綁定樣板,但我也能擺脫所有的RadioButton定義? – 2012-02-05 00:00:05
是的,它確實... – 2012-02-05 00:13:47