After reading this post
http://ko.infragistics.com/community/blogs/josh_smith/archive/2008/06/06/binding-a-xamdatagrid-field-property.aspxI ran its code and it ran also. I made a few changes to it and they still worked. My changes are like this
using System.Windows;using Infragistics.Windows.DataPresenter;using System.Collections.Generic;using System.IO;using System.Text.RegularExpressions;using System.Windows.Data;using System.Windows.Controls;
namespace XamDataGridWithBoundField{ public partial class Window1 : Window { public const string VIEW_MODEL_RESOURCE_NAME = "MyViewModel";
public Window1() { Person[] people = new Person[] { new Person("Boss Hogg", 42, "hogg.jpg"), new Person("Johann Bach", 50, "bach.jpg"), new Person("Mugatu", 39, "mugatu.gif"), new Person("Simon Wolcott", 24, "wolcott.jpg") };
DataContext = new CommunityViewModel(people);
}
public new object DataContext { get { return base.DataContext; } set { if (Resources.Contains(VIEW_MODEL_RESOURCE_NAME)) Resources.Remove(VIEW_MODEL_RESOURCE_NAME);
base.DataContext = value; Resources.Add(VIEW_MODEL_RESOURCE_NAME, value); } } }}
<Window x:Class="XamDataGridWithBoundField.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:local="clr-namespace:XamDataGridWithBoundField" Title="Window1" Width="400" Height="400"> <Window.Resources> <Style x:Key="PhotoCellStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Width="60" Height="60" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </Window.Resources> <StackPanel Orientation="Vertical"> <ToolBar DockPanel.Dock="Top"> <CheckBox Content="Show Photos" IsChecked="{Binding Path=ShowPhotos}" /> </ToolBar>
<igDP:XamDataGrid AutoFit="True" DataSource="{Binding Constituents}"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Label="Name" Name="Name" /> <igDP:Field Label="Photo" Name="ImageUri" Visibility="{Binding ShowPhotos, Source={StaticResource {x:Static local:Window1.VIEW_MODEL_RESOURCE_NAME}}, Converter={StaticResource BooleanToVisibilityConverter}}"> <igDP:Field.Settings> <igDP:FieldSettings CellMaxWidth="70" LabelMaxWidth="70" CellValuePresenterStyle="{StaticResource PhotoCellStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Label="Age" Name="Age" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> <ContentControl x:Name="abc" /> </StackPanel></Window>
Now I am wondering if this can be done to dynamically generated fields. Why? Because my grid's layout is dynamic.
Hello,
I am just checking if you require any further assistance on the matter.
I have been looking into your question and if you do not specify the fields for which to apply the CellValuePresenter style it will be applied for each field in the XamDataGrid. You need to set for which fields the style will be applied if you want some specific fields, not all.