如何通过 Xaml 行为设置图像源 属性?
How to set Image Source property by Xaml Behaviors?
我想更改每个 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>
你几乎是纠正了一个小错误。把你的 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>
我想更改每个 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>
你几乎是纠正了一个小错误。把你的 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>