Home > Blockchain >  WPF Multibuilding 2 Values to the same Property
WPF Multibuilding 2 Values to the same Property

Time:10-25

I have a table, and when the user would like to mark a row. he can click on button and mark it. so I wrote a converter for the property, that if its true it return color(yellow) and if false it return white, however it Deletes the default style when user select a row in the table.

I was thinking of using Multibuilding once for mark, and one for selected. however I am not understand what the syntax should be in WPF.

attaching the code I wrote, will appreciate a code examples.

WPF:

    <Style TargetType="syncfusion:GridCell" x:Key="ComCell">
        <Setter Property="Foreground" Value="{Binding COMPort , Converter={StaticResource CVconverters }  }" />
        <Setter Property="Background" Value="{Binding isBookMarked, Converter={StaticResource BookMarkConverter}}"></Setter>
    </Style>

C#:

public class BookMarkConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        string valStr = value.ToString();
        
       
            if (valStr == "True")
            {
                return Brushes.Yellow;
            }
            else
            {

            }
       

        return Brushes.White;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

CodePudding user response:

Instead of returning Brushes.White from the converter, you could return Binding.DoNothing from the converter if you simply don't want to change the background.

You could also base your Style on the default one:

<Style TargetType="syncfusion:GridCell" x:Key="ComCell"
       BasedOn="{StaticResource {x:Type syncfusion:GridCell}}">
  • Related