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
315
How to set Textblock dynamically based on DataItem text
posted

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.

Parents
  • 315
    Suggested Answer
    Offline posted

    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 };
            }
        }
Reply Children