I created a control with 3 PART_s, one PART_ changes depending on the type associated with it, however, the values changed in the control do not update the binding, it seems to work like a OneWay binding.
The part of the code that I believe is important here:
<DataTemplate x:Key="BooleanDAView" DataType="{x:Type sys:Boolean}"> <CheckBox IsChecked="{Binding ., Mode=TwoWay}"/> </DataTemplate> <DataTemplate x:Key="DateTimeDAView" DataType="{x:Type sys:DateTime}"> <extToolkit:DateTimePicker Value="{Binding ., Mode=TwoWay}"/> </DataTemplate> <DataTemplate x:Key="Int32DAView" DataType="{x:Type sys:Int32}"> <extToolkit:IntegerUpDown Value="{Binding ., Mode=TwoWay}"/> </DataTemplate> <DataTemplate x:Key="StringDAView" DataType="{x:Type sys:String}"> <TextBox Text="{Binding ., Mode=TwoWay}"/> </DataTemplate>
....
<ContentControl x:Name="PART_Content" Grid.Row="0" Grid.Column="1" Margin="{TemplateBinding Padding}" VerticalAlignment="Center" VerticalContentAlignment="Center" Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" > <ContentControl.ContentTemplateSelector> <controls:TypeBasedDataTemplateSelector> <controls:TypeBasedDataTemplateSelector.Templates> <controls:TypedDictionary> <sys:String x:Key="{x:Type sys:Boolean}">BooleanDAView</sys:String> <sys:String x:Key="{x:Type sys:DateTime}">DateTimeDAView</sys:String> <sys:String x:Key="{x:Type sys:Int32}">Int32DAView</sys:String> <sys:String x:Key="{x:Type sys:String}">StringDAView</sys:String> </controls:TypedDictionary> </controls:TypeBasedDataTemplateSelector.Templates> </controls:TypeBasedDataTemplateSelector> </ContentControl.ContentTemplateSelector> </ContentControl>
For the content, I also tried ... RelativeSource={RelativeSource AncestorType=local:DABaseControl} , but no change.
If the DataTemplate Binding uses "{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" , the template does not change after installation.
Or is there a better way to do this?
thank
c # wpf binding xaml
user1049761 Nov 16 '11 at 13:50 2011-11-16 13:50
source share