如何通过Xaml Behaviors设置图像源属性?

3
我想在每个FlipView项目上更改背景图片。我尝试了这段代码,但它会触发错误“Only IBehavior types are supported in a BehaviorCollection.”。
如何正确设置图像源?
<Grid>
    <i:Interaction.Behaviors>
        <core:DataTriggerBehavior
            Binding="{Binding SelectedIndex, ElementName=TourFlipView}"
            ComparisonCondition="Equal"
            Value="1" />
        <core:ChangePropertyAction
            TargetObject="{Binding ElementName=TourFlipViewBackgroundImage}"
            PropertyName="Source"
            Value="ms-appx:///Assets/Images/2.png" />
    </i:Interaction.Behaviors>

    <Image
        x:Name="TourFlipViewBackgroundImage"
        Source="ms-appx:///Assets/Images/1.png" />

    <FlipView
        x:Name="TourFlipView">
        ...
    <FlipView/>
</Grid>
1个回答

4
你做得几乎正确,只有一个小错误。把你的ChangePropertyAction放在DataTriggerBehavior里面。
<i:Interaction.Behaviors>
    <core:DataTriggerBehavior
        Binding="{Binding SelectedIndex, ElementName=TourFlipView}"
        ComparisonCondition="Equal"
        Value="1" >
        <core:ChangePropertyAction
            TargetObject="{Binding ElementName=TourFlipViewBackgroundImage}"
            PropertyName="Source"
            Value="ms-appx:///Assets/Images/2.png" />
    </core:DataTriggerBehavior> 
</i:Interaction.Behaviors>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接