Alternative to Triggers on WP8

前端 未结 2 1193
陌清茗
陌清茗 2021-01-21 05:41

I\'ve read that Triggers are not supported in XAML for WP8. What\'s the alternative approach? I wanted to use a trigger to change the background image of a button w

相关标签:
2条回答
  • 2021-01-21 06:14

    Please try this. Windows phone triggers msdn

    Here I binded the image data trigger with my Boolean property , when the Boolean property is changed it will trigger and the setter will fire. Make sure you properties are implemented with INofityPropertyChanged

     xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" x:Class="XXX_XXXX"
    <Image Source="/Assets/Images/Tick.png"
                       Stretch="None"
                       HorizontalAlignment="Stretch" 
                       VerticalAlignment="Top">
                    <interactivity:Interaction.Triggers>
                        <ec:DataTrigger Binding="{Binding IsTapped}" Value="True">
                            <ec:ChangePropertyAction PropertyName="Source">
                                <ec:ChangePropertyAction.Value>
    
                                    <BitmapImage UriSource="/Assets/Images/Close.png"/>
                                </ec:ChangePropertyAction.Value>
                            </ec:ChangePropertyAction>
                        </ec:DataTrigger>
                    </interactivity:Interaction.Triggers>
                </Image>
    
    0 讨论(0)
  • 2021-01-21 06:35

    You could, potentially just attach an event handler for the "Tap" event for the image. Without code examples, I'm not too sure how much I can help; however, I've pasted some code below:

    XAML

                    <Image Source="/Assets/awesomeImg.png" Tap="AwesomeImg_Tap"/>
    

    Code Behind (C#)

    private void AwesomeImg_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
          YourImageName.ImageSource = //code here to URI of image
        }
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题