Hello, How can I apply style for dynamic fields.
I wont know the number of columns, until runtime. But, I want to format columns based on its type.. Ex: If the value is Deceimal change Foreground based on its value.
I thought of applying Style for all the columns, and Converter has the logic to identity whether the value is of certain type. Below code doesnt work ..
<Style TargetType="{x:Type igDP:CellValuePresenter}"><Setter Property="Foreground" Value="{Binding Path=Value, Converter={StaticResource ResourceKey=fontcolorConverter}}" /></Style>
System.Windows.Data Error: 40 : BindingExpression path error: 'Value' property not found on 'object' ''DataRecord' (HashCode=39116207)'. BindingExpression:Path=Value; DataItem='DataRecord' (HashCode=39116207); target element is 'CellValuePresenter' (Name=''); target property is 'Foreground' (type 'Brush')
Any ideas?
Selva,
If the key is not specified, it's true, the style will apply to all fields.
Thank you,Sam
Sam, Thanks for the solution. But, this will apply for all the fields and also I needed to apply style based on its value. Below is the code I used.
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Foreground" Value="{Binding Path=Value, RelativeSource={RelativeSource Self}, Converter={StaticResource ResourceKey=colorConverter}}" /> </Style>
Hello Selva,
Here is an example for assigning Field Settings to a field that is created dynamically. The LabelPresneterStyle is defined in XAML:
Field fld = new Field()
{
Name = "NewField",
Label = "New Field"
};
fld.Settings.LabelPresenterStyle = this.Resources["lbl2"] as Style;
e.FieldLayout.Fields.Add(fld);
<Style x:Key="lbl2" TargetType="{x:Type igDP:LabelPresenter}">
<Setter Property="Background" Value="Red"/>
<Setter Property="TextBlock.FontWeight" Value="Bold"/>
<Setter Property="TextBlock.Text" Value="Hello"/>
</Style>
Let me know if you have any questions.
Let me simplify my question,
How can I assign Field settings at run time. Number of columns and Name of the columns are known only at run time.