I have value converter that converts the visibilty aspect of a control when its text starts with http or not. Below is the code.
public class HTTPVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool boolVisbility = (value != null) && value.ToString().StartsWith("http");
boolVisbility = (parameter != null) ? !boolVisbility : boolVisbility;
return boolVisbility ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
I have put this code in the ToolViewe.xaml.cs . I am trying to use the above converter in my datagrid as follows:
<slData:DataGrid x:Name="CustomerDetailsDataGrid"
ItemsSource=" {Binding SingleReturnedItemAttributes}"
AutoGenerateColumns="False"HeadersVisibility="None"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible" MaxHeight="350"
MaxWidth="350">
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding=" {Binding Path=Key}"
FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path= Value}" Visibility="
{Binding Path=IsControlVisible,Converter={StaticResource theHttpVisbilityConverter}}"
/>
<slData:DataGridTextColumn Binding="{Binding Path= Value}" Visibility="
{Binding Path=IsControlVisible ,Converter={StaticResource theHttpVisbilityConverter},
ConverterParameter=reverse}"
/>
</slData:DataGrid.Columns>
What should I be using for the Binding Path of the Visibility? I have tried using the following property by declaraing the code in ToolViewModel.cs. But does not work. Please guide this newbie.
bool isControlVisible = false;
public bool IsControlVisible
{
get { return isControlVisible; }
set
{
isControlVisible = value;
this.RaisePropertyChanged(() => this.IsControlVisible);
}
}
This is the error: Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Windows.Visibility'.