I've xamdatagrid which is getting bind with ObservableBindingCollection.
I am showing the status which is coming from result set as below.
<Grid>
<TextBlock Text="Status:" FontFamily="Microsoft Sans Serif" FontSize="8.25 pt"/> <TextBlock Margin="5,0,0,0" FontWeight="Bold" FontFamily="Microsoft Sans Serif" FontSize="8.25 pt" Text="{Binding Path=DataItem.StatusText}" />
</Grid>
I want to modify "Status:" based on the DataItem.StatusText.
E,g.
if (DataItem.SatusText == "Pending")
{
"Status:" should display as "Status from Dev:"
}
Else
"Status:" should display as "Status from Prod:"
How to set Textblock dynamically based on DataItem text.
I found the solution that this can be achieve using Converter. Please let me know if any other solution you found.
public class StatusConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string status = value as string; if (status == "Pending") { return "Status from Dev"; } return "Status from Prod"; } public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture) { return new object[] { value }; } }
Hello pramod3861,
Thank you for your post(s).
I am glad that you have found a solution for this issue. Coincidentally, this was the same solution that I was going to recommend that you use, as a converter would allow you to look at a particular value and then return something else dynamically, which is what it appears you are looking to do.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Thanks for your reply. We are good with this :).
Regards,
Pramod Pawar