0

I have the following situation, where I have a Combobox1 and then I have TextBlock (ImportantText) in XAML. What I'm trying to do, is to trigger TextBlock's EventTrigger, and thus the Storyboard when user changes the Combobox's selection. I would like to do this in the xaml-side only.

Any suggestions?

    <ComboBox Name="Combobox1" Grid.Column="1" Grid.Row="0" Margin="0,-5,0,0" ItemsSource="{Binding Stuff}"
 SelectedItem="{Binding SelectedStuff}" ></ComboBox>

                <TextBlock Name="ImportantText" Grid.Column="1" Grid.Row="1" Text="This text should appear after user changes the combobox's selection!" TextWrapping="Wrap">
                    <EventTrigger RoutedEvent=" I'm not sure how to reference Combobox1 here! " ></EventTrigger>
                    <BeginStoryboard>

                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ImportantText" Storyboard.TargetProperty="Opacity" AutoReverse="False" From="0.0" To="1.0" Duration="0:0:5"></DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>

                </TextBlock>
4
  • Use the SourceName property to refer to the combobox. learn.microsoft.com/en-us/dotnet/api/… Commented Dec 8, 2023 at 14:17
  • Thanks! I tried that, but how do I refer to the event, when user selects something? All I can find by using the SourceName are properties like IsEnabled etc. Commented Dec 8, 2023 at 14:40
  • Hhm, seems difficult to use SourceName and TargetName in a normal style (not template). Maybe you need to do it in code-behind. Commented Dec 8, 2023 at 15:30
  • It seems so. It is very easy to do by binding to another boolean value and using that to show/hide the text, but it would have been nice to do it in XAML alone. Thanks for your suggestions! Commented Dec 11, 2023 at 7:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.