【问题标题】:Change image source when loaded event of other image加载其他图像的事件时更改图像源
【发布时间】:2016-09-21 04:57:15
【问题描述】:

我正在使用新的 MS 技术 UWP。我在 DataTemplate、CopyImage 和 MainImage 中有 2 个图像。这是因为图像闪烁,当源被改变时。所以我想问一下,当MainImage的Loaded事件被触发时,如何设置CopyImage的来源?在 WPF 中我可以使用 DataTriggers,但它们不在 UWP 中。我想在 XAML 中这样做,而不是在代码隐藏中。

非常感谢大家

编辑

<Image Grid.Column="0" x:Name="MainImage" Source="{x:Bind ImageStatusUri, Mode=OneWay}" Margin="0,8,12,8">
 <Image.Triggers>
   <EventTrigger RoutedEvent="Image.Loaded">                   
   </EventTrigger>
 </Image.Triggers>

【问题讨论】:

标签: wpf windows-runtime winrt-xaml uwp uwp-xaml


【解决方案1】:

希望你使用Template10

<Page  xmlns:interact="using:Microsoft.Xaml.Interactivity" 
    xmlns:interactcore="using:Microsoft.Xaml.Interactions.Core">
...
    <Image Grid.Column="0" x:Name="MainImage" Source="{x:Bind ImageStatusUri, Mode=OneWay}" Margin="0,8,12,8" >

                    <interact:Interaction.Behaviors>
                    <interactcore:EventTriggerBehavior EventName="Loaded">
                        <interactcore:ChangePropertyAction PropertyName="Source" Value="" TargetObject="{Binding ElementName=CopyImage}"/>
                    </interactcore:EventTriggerBehavior>
                </interact:Interaction.Behaviors>
            </Image>
</Page>

【讨论】:

  • 谢谢伙计。我试过了,但是 CopyImage 比 MainImage 大,而且图片的大小是一样的。当我更改图像时,只有 MainImage 会更改,CopyImage 不会更改。所以我认为,Loaded 事件只会触发一次。
  • 您说要在主图像加载时加载复制图像对吗?
  • 是的。触发 MainImage 的 Loaded 事件后,我需要设置 CopyImage 的来源
  • 所以它必须只触发一次对吗?我不明白你为什么提到尺寸。你能详细说明一下吗?
  • 不止一次。因为我有联系人列表视图。而当一些联系人改变在线/离线状态时,图像也会改变。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-20
  • 1970-01-01
  • 2011-08-28
  • 2012-07-15
  • 2019-01-02
  • 2014-12-06
  • 2016-02-20
相关资源
最近更新 更多