views:

21

answers:

1

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}}"
A: 

Looks to me like you're trying to your dependency properties on a ComboBox, even though they're defined by your DataDependentControl. If the visibility of the child controls is tied to the visibility of the ComboBox, why not just do this?

<Views:DataDependentControl x:Name="typeValue">
    <StackPanel x:Name="container">
        <TextBox x:Name="TextBoxControl" Visibility="{Binding Visibility, ElementName=typeValue}"/>
        <Controls:Calendar x:Name="CalendarControl" HorizontalAlignment="Left"  Visibility="{Binding Visibility, ElementName=typeValue}"/>
        <ComboBox x:Name="ComboBoxControl"  Visibility="{Binding Visibility, ElementName=typeValue}"/>
    </StackPanel>
</Views:DataDependentControl>

Or, even better:

<Views:DataDependentControl x:Name="typeValue">
    <StackPanel x:Name="container" Visibility="{Binding Visibility, ElementName=typeValue}">
        <TextBox x:Name="TextBoxControl"/>
        <Controls:Calendar x:Name="CalendarControl" HorizontalAlignment="Left"/>
        <ComboBox x:Name="ComboBoxControl"/>
    </StackPanel>
</Views:DataDependentControl>

HTH,
Kent

Kent Boogaart
I have added information after words "All in all"The visibility is selective. Not all controls should visible or collapsed
Dmitry
BTW, your way would be good if to develop IValuConvertor for each child control inside DataDependentControl and to databind Visibility to outside combobox value.
Dmitry
There was an error in description: "typeValue" is not a combobox, but common user control which defines DataType property and child controls Visibility property is updated according to DataType
Dmitry