I have DataDependentControl with dependency properties defined: TextVisibility, CalendarVisibility, ComboControlVisibility. When I select some values in outside combobox with enumerated datatypes, the properties mentioned above are updated to Visibility enumeration value, but binding doesn't update Visibility property on inside controls:
<Views:DataDependentControl x:Name="typeValue">
<StackPanel x:Name="container">
<TextBox x:Name="TextBoxControl" Visibility="{Binding ElementName=typeValue, Path=TextVisibility, Mode=OneWay}"/>
<Controls:Calendar x:Name="CalendarControl" HorizontalAlignment="Left" Visibility="{Binding ElementName=typeValue, Path=CalendarVisibility}"/>
<ComboBox x:Name="ComboBoxControl" Visibility="{Binding ElementName=typeValue, Path=ComboControlVisibility}"/>
</StackPanel>
</Views:DataDependentControl>
DataDependentControl has DataType property. According to DataType I hide or collapse child controls via following properties: ComboControlVisibility, CalendarVisibility or TextVisibility
DataType property within DataDependentControl is defined as follows:
public static readonly DependencyProperty DataTypeProperty = DependencyProperty.Register(
DataTypePropertyName,
typeof (DataTypeEnum),
typeof (DataDependentControl),
new PropertyMetadata(ValueChangedCallback));
ValueChangedCallback function is defined as follows:
private static void ValueChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var thisObject = (DataDependentControl)d;
var newValue = (DataTypeEnum) e.NewValue;
switch (newValue)
{
case DataTypeEnum.Bool:
thisObject.ComboControlVisibility = Visibility.Visible;
thisObject.CalendarVisibility = Visibility.Collapsed;
thisObject.TextVisibility = Visibility.Collapsed;
....
Example of TextVisibility, CalendarVisibility or ComboControlVisibility is here:
public static readonly DependencyProperty TextVisibilityProperty = DependencyProperty.Register(
TextVisibilityPropertyName,
typeof (Visibility),
typeof (DataDependentControl),
null);
All in all:
Inside the <StackPanel/>
:
If selected datatype is "string" there should be visible
<TextBox x:Name="TextBoxControl"/>
If selected datatype is "DateTime" there should be visible
<Controls:Calendar/>
If selected datatype is "Boolean" there should be visible
<ComboBox/>
DataDependentControl has "DataType" property which is defined in combobox. "DataType" is databound:
<Views:DataDependentControl x:Name="typeValue"
DataType="{Binding SelectedItem, ElementName=DataTypes, Converter={StaticResource DataTypeReverseConverter}}"