Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
440
Bind the entire row object to a single column
posted

Hi,

I am using xamwebgrid. In the grid I want to show an image column so I am using the TemplateColumn and applying datatemplate that contains four images. Now based on two properties in my Object that is bound to the row, I want to show only two of the images.

I can use a value converter to show/hide the images. The only problem is I can bind my column to only one property in my Object. So in the valueconverter I can pass only one property as multibinding is not present in silverlight.

Is there anyway I can bind my entire Object out of the List to one column. That way I can write all the show/hide logic in a single valueconverter.

Parents
No Data
Reply
  • 6912
    Suggested Answer
    posted

    Hi,

    You can pass the entire object to the value converter like that:

    <ig:XamGrid>
    	<ig:XamGrid.Resources>
    		<local:MyConv x:Key="MyConv" />
    	</ig:XamGrid.Resources>
    	<ig:XamGrid.Columns>
    		<ig:TemplateColumn Key="MyColumnKey">
    			<ig:TemplateColumn.ItemTemplate>
    				<DataTemplate>
    					<Image ... other settings ...
    						   Visibility="{Binding Converter={StaticResource MyConv}}" />
    				</DataTemplate>
    			</ig:TemplateColumn.ItemTemplate>
    		</ig:TemplateColumn>
    	</ig:XamGrid.Columns>
    
    public class MyConv : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return [... condition ...] ? Visibility.Visible : Visibility.Collapsed;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return DependencyProperty.UnsetValue;
        }
    }

    HTH

Children