question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataTrigger properties on child controls

See original GitHub issue

I would like to be able to change the TextColor of the label in response to the pressed state of the ContentView (similar to the sample here). When TouchEffect was previously a control, I did something like this:

...
<touch:TouchView x:Name="touchView">
<Label>
     <Label.Triggers>
          <DataTrigger Binding="{Binding Source={x:Reference touchView}, Path=State}" TargetType="Label" Value="Pressed">
               <Setter Property="TextColor" Value="Red" />
          </DataTrigger>
     </Label.Triggers>
</Label>
</touch:TouchView>

Now that it’s an effect, I tried doing something like this but no luck:

<Label.Triggers>
     <DataTrigger Binding="{Binding Source={x:Reference ContentViewName}, Path=(touch:TouchEff.State)}" TargetType="Label" Value="Pressed">
          <Setter Property="TextColor" Value="Red" />
     </DataTrigger>
</Label.Triggers>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AndreiMisiukevichcommented, Mar 5, 2020

Then only:

    <StackLayout>
        <ContentView Padding="200"
                     x:Name="content"
                     touch:TouchEff.PressedBackgroundColor="Red"
                     touch:TouchEff.RegularBackgroundColor="Green"
                     HorizontalOptions="CenterAndExpand"
                     VerticalOptions="CenterAndExpand">
            <ContentView.Effects>
                <touch:TouchEff Completed="Handle_TouchCompleted"/>
            </ContentView.Effects>

            <ContentView.Triggers>
                <Trigger Property="touch:TouchEff.State" Value="Pressed" TargetType="ContentView">
                    <Setter Property="ClassId" Value="Pressed" />
                </Trigger>
            </ContentView.Triggers>

            <Label FontSize="60"
                   HorizontalOptions="Center"
                   Text="CLICK ME"
                   TextColor="White"
                   VerticalOptions="Center">
                <Label.Triggers>
                    <DataTrigger Binding="{Binding Source={x:Reference content}, Path=ClassId}" TargetType="Label" Value="Pressed">
                        <Setter Property="TextColor" Value="Red" />
                    </DataTrigger>
                </Label.Triggers>
            </Label>
        </ContentView>
    </StackLayout>
0reactions
AndreiMisiukevichcommented, Mar 5, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

How would you bind a DataTrigger to a Child property from ...
1 Answer 1 ... This property has no logic, it's just used for "connecting" controls any way you like. ... I wouldn't recommend...
Read more >
WPF - How to access child properties in XAML not using ...
I know how to access parent properties to change child properties in XAML. ... Triggers> <DataTrigger Binding="{Binding ...
Read more >
DataTrigger Class (System.Windows)
Represents a trigger that applies property values or performs actions when the bound data meets a specified condition.
Read more >
WPF Setter Property of named child : r/dotnet
In my WPF application, I have the following Style: <Style TargetType="ListViewItem" x:Key="YouTubeItem"> <Setter Property="Template"> ...
Read more >
Wpf – UserControl property trigger for child control
Best Solution. Use a DataTrigger instead of a normal Trigger which is for internal property changes, it has a Binding -Property where you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found