Search code examples
wpfxamlmultidatatrigger

trim string value in a multitrigger without a converter?


I have a MultiTrigger that I use to color the values of my DataGrid control. This trigger was working fine until recently when I discovered the color no longer worked. I looked at the database and discovered that blank spaces were trailing my value and thus my trigger comparison of the value would always fail.

I was wondering if there is a stringformat or a trim function that I can do inline with my xaml so that I don't have to write a converter class to just do "value.trim() return value"

Here is my xaml:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <!-- this is the actual grid column element binding -->
        <Condition Binding="{Binding FieldName, RelativeSource={RelativeSource Self}}" Value="SocketState"/>
        <!-- this checks the value on the element referenced ^here-->
        <Condition Binding="{Binding SocketState}" Value="Connected" />
    </MultiDataTrigger.Conditions>

    <Setter Property="Background" Value="{StaticResource YellowGreenGradientBrush}"/>
</MultiDataTrigger>

Solution

  • Fixed my issue by trimming in my sql view. No wpf code change necessary.