我試圖託管數據模板內的內容控件。WPF - 通過代碼託管數據模板內的內容控件
正是與此類似: Putting a ContentControl *inside* a WPF DataTemplate?
我成功地通過XAML這樣做。我想通過代碼做同樣的事情。
我創建了一個風格:
<Style x:Key="radioButtonAddtruefalse">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<RadioButton Content="True" IsChecked="{Binding Value}"></RadioButton>
<RadioButton Content="False" IsChecked="{Binding Value, Converter={StaticResource _invertedBooleanConverter}}"></RadioButton>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
和數據模板中:
<DataTemplate>
<ContentControl Style="{StaticResource radioButtonAddtruefalse}"> /ContentControl>
</DataTemplate>
我試着通過代碼實現這一點,但發現的DataTemplate下沒有什麼可以讓我舉辦一個ContentControl中。有什麼建議麼?
看 http://stackoverflow.com/questions/5471405/create-datatemplate-in-code-behind – 2013-03-06 11:14:47