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
630
changing a CellValuePresenterStyle at runtime
posted

Hi

I have managed to work out (thanks to examples) how to change a cells background, and other properties based on data trigger. Conditional formatting etc...

I have an unbound field that displays an image. Based on a cell value I wish to either change the image or change the cellValuePresenterStyle to point to another style. For example is cell value = x then use cellpresenterstyle x, if y then use cellpresenterstyle y

The code looks messy in this here but no so if you take it out and into VS

I have this xaml for the unbound field:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key

="UserImage1">

 

 

 

 

<Setter Property

="Template">

 

 

 

 

<Setter.Value

>

 

 

 

 

<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter

}">

 

 

 

 

<Grid Width="50" Height

="50">

 

 

 

 

<Image

 

 

 

Margin="0"

 

 

 

HorizontalAlignment

="Center"

 

 

 

VerticalAlignment

="Top"

 

 

 

Source="{StaticResource BuddyBlue}" Width="50" Height

="50"/>

 

 

 

 

</Grid

>

 

 

 

 

</ControlTemplate

>

 

 

 

 

</Setter.Value

>

 

 

 

 

</Setter

>

 

 

 

 

</Style

>

 

 

 

 

This is my unbound field xaml from the grid:

 

 

 

 

 

 

 

 

 

<igDP:UnboundField Name="UserImage" Label

="UserImage">

 

 

 

 

<igDP:Field.Settings

>

 

 

 

 

<igDP:FieldSettings CellMinWidth="50" CellWidth="50"

 

 

 

CellValuePresenterStyle="{StaticResource UserImage1

}" />

 

 

 

 

</igDP:Field.Settings

>

 

 

 

 

</igDP:UnboundField

>

This is how I manage my changes to the foreground and background properties:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

public

winUsers()

{

InitializeComponent();

Title =

 

 

"Users"

;

xamDataCarousel1.DataSource = GetUsers().DefaultView;

xamDataCarousel1.FieldLayoutInitialized +=

 

 

new EventHandler<Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs

>(xamDataCarousel1_FieldLayoutInitialized);

}

 

 

 

void xamDataCarousel1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs

e)

{

 

 

 

//Get the CarName field

 

 

 

Field idField = e.FieldLayout.Fields["Name"

];

 

 

 

//Create the style in code behind

 

 

 

Style s = new Style(typeof(CellValuePresenter

));

 

 

 

//Create DataTrigger

 

 

 

DataTrigger trigger1 = new DataTrigger

();

 

 

 

//Create a Setter

 

 

 

Setter setter1 = new Setter(CellValuePresenter.BackgroundProperty, Brushes

.Red);

 

 

 

Setter setter2 = new Setter(CellValuePresenter.ForegroundProperty, Brushes

.White);

 

 

 

//Create a Binding

 

 

 

Binding binding = new Binding("Cells[SomeValue].Value"

);

 

 

 

//Set the trigger properties

trigger1.Value =

 

 

"X"

;

trigger1.Binding = binding;

 

 

 

//Add the setter in the trigger

trigger1.Setters.Add(setter1);

trigger1.Setters.Add(setter2);

 

 

 

//Add the trigger in the style

s.Triggers.Add(trigger1);

 

idField.Settings.CellValuePresenterStyle = s;

}