locked
Problem with Binding (Conversion class) RRS feed

  • Question

  • I have this problem: I've written this XAML <ListBoxVisibility="{BindingIsDataLoaded,Converter=BoolToVisibility}" ItemsSource="{Binding ...}" .............../>

    and I've written this C# class:

    public

    classBoolToVisibilityConverter: IValueConverter


        {

           

    publicobjectConvert(objectvalue, TypetargetType, objectparameter, System.Globalization.CultureInfoculture)

            {

               

    if((bool)value)

                {

                   

    returnVisibility.Visible;

                }

               

    else


                {

                   

    returnVisibility.Collapsed;

                }

            }

    publicobjectConvertBack(objectvalue, TypetargetType, objectparameter, System.Globalization.CultureInfoculture)

    {

    thrownewNotImplementedException();

            }

        }

    However I get this error (not at Runtime): "Errore 1 Il TypeConverter per "IValueConverter" non supporta la conversione da una stringa." which means "The TypeConverter for "IValueConverter" doesn't support conversion from a string"...in fact I'm not trying to convert from a string, but from a bool value (IsDataLoaded is boolean). Why this happens?

    Tuesday, August 27, 2013 1:23 PM

All replies

  • Hi,

    I guess you declaring the converter wrong here.

    I guess you have declared the Converter as a local resource . something like this :

    <phone:PhoneApplicationPage.Resources>
            <ResourceDictionary>
    
                           <local:BoolToVisibilityConverter x:Key="BoolToVisibility" />
            </ResourceDictionary>
        </phone:PhoneApplicationPage.Resources>

    In the code you should use like this :

    <ListBoxVisibility="{BindingIsDataLoaded,
    Converter={StaticResource BoolToVisibility}}" ItemsSource="{Binding ...}" .............../>

    - Girija


    Please mark responses as answered if it helped you.. This helps others... - Girija Shankar Beuria

    Tuesday, August 27, 2013 1:40 PM
  • write this code in your xaml to access the converter in xaml
    xmlns:app="clr-yournamespacename:BoolToVisibilityConverter"

    and after that add resource of this like 

    <Grid.Resources>
                <app:BoolToVisibilityConverter x:Key="myConverterKey" />
     </Grid.Resources>

    now bind the value with this key like 

    Value="{Binding Converter={StaticResource myConverterKey}}"

    then your converter work fine . 

    Tuesday, August 27, 2013 2:08 PM