0

I have no idea what is wrong, and how I am supposed to solve the error. Strangely enough, the data triggers work fine.

    <Style TargetType="Border">
        <Setter Property="Background" Value="{StaticResource HeaderBackgroundBrush}"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding State}" Value="{StaticResource ErrorState}">
                <Setter Property="Background" Value="OrangeRed"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding State}" Value="{StaticResource ProductionState}">
                <Setter Property="Background" Value="Green"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

ProductionState and Error states are enum values referenced in XAML:

    <machineControl:MachineControllerState x:Key="ErrorState">Error</machineControl:MachineControllerState>
    <machineControl:MachineControllerState x:Key="ProductionState">Production</machineControl:MachineControllerState>

The State binding references to the view model which is "a normal" property which supports IPropertyChanged (from mvvm lights lib)

    public MachineControllerState State
    {
        get => state;
        set { Set(() => State, ref state, value); }
    }

visual studio shows the error in error list:

After a data trigger is in use (sealed), it cannot be modified

Update: to be clear, the solution compiles fine, and runtime everything works as expected.

bas
  • 13,550
  • 20
  • 69
  • 146
  • Oh sorry. Vs2017 latest update – bas Nov 21 '18 at 08:58
  • Shouldnt be the case then. Try Clean And Rebuild entire Solution. As others say that works for them - clearing the Error. – Prateek Shrivastava Nov 21 '18 at 09:00
  • The phrasing is not very helpful, it strikes me that "committed" would be a bit more helpful than "sealed". But at the root the xaml does not interact well with the code you wrote. Seems it wants to tinker with the trigger. We can't see the code. Temporarily commenting out stuff might well be a decent way to locate it. – Hans Passant Nov 21 '18 at 09:30
  • What is `ProductionState`, `ErrorState` and `State`? Can you provide the codebehind? – Kevin Kouketsu Nov 21 '18 at 10:03
  • Updated the question with the missing parts. When I comment out the two databindings the error dissapears. When I uncomment them, the error returns (immediately, no need to rebuild). – bas Nov 21 '18 at 12:15
  • You already tried to refer your enum namespace on XAML and just use something like: `{x:Static namespacename:EnumName.EnumValue}` – Kevin Kouketsu Nov 21 '18 at 12:37
  • 1
    @KevinKouketsu {x:Static machineControl:MachineControllerState.Production} is the fix. thx! a nicer look this way w/o errors :). Drop it as answer and i'll accept it – bas Nov 21 '18 at 15:36

1 Answers1

1

You can refer your enum directly from your codebehind. Something like:

{x:Static namespacename:EnumName.EnumValue}

Reference: How can I use enum types in XAML?

Kevin Kouketsu
  • 786
  • 6
  • 20