Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF, change bindings based upon a trigger, possible?

I have a usercontrol, that when one property changes, the bindings change for a number of different embedded controls (in the same user control). Before I waste too much time, is this something that can be done with a Trigger or DataTrigger? I can do it in code behind but this seems 'dirty'.

like image 902
jeff Avatar asked Jun 14 '09 04:06

jeff


1 Answers

Sure, the following changes the Text binding of shiftButtonText when the IsPressed property of the current DataContext changes. Is this the type of thing that you're looking for?

    <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=IsPressed}" Value="True">
            <Setter TargetName="shiftButtonText" Property="Text" Value="{Binding Path=PressedText}"/>
        </DataTrigger>
    </DataTemplate.Triggers>

Hope this helps,

like image 129
Binary Worrier Avatar answered Nov 15 '22 19:11

Binary Worrier