image - LongListSelector 项模板中图像控件的 ChangePropertyAction

标签 image triggers windows-phone-8 longlistselector

我有一个很长的列表选择器,并且有一个数据模板作为项目模板,其中包含图像。我希望源根据模型的属性进行更改。我尝试使用转换器,但无法让它工作。

现在我正在尝试使用触发器。我有:

<Image Name="MovieThumbnail">
<i:Interaction.Triggers>
    <ei:DataTrigger Binding="{Binding DataContext.IsCategoryCurrent,ElementName=LayoutRoot}" Value="true">
        <ei:ChangePropertyAction TargetObject="{Binding ElementName=MovieThumbnail}" TargetName="Source" Value="{Binding Path=Image120x170}" PropertyName="Source"/>
    </ei:DataTrigger>

    <ei:DataTrigger Binding="{Binding DataContext.IsCategoryCurrent,ElementName=LayoutRoot}" Value="false">
        <ei:ChangePropertyAction TargetObject="{Binding ElementName=MovieThumbnail}" TargetName="Source" Value="{x:Null}" PropertyName="Source"/>
    </ei:DataTrigger>
</i:Interaction.Triggers>
</Image>

它几乎按照我想要的方式工作,除了图像会重复自己。就像一部电影里有另一部电影的画面一样。我认为这是因为我通过元素名称绑定(bind)并且图像控件有多个实例(每个项目一个),但我认为它们无法看到彼此。非常感谢任何帮助。

编辑:

经过进一步调查,似乎是由于长列表选择器而发生这种情况。

我首先加载 40 个项目,然后加载另外 40 个项目,但是第二批 40 个项目获取了第一批的图片。如果我引发属性更改事件,则第二批中的图片将设置在所有重复的项目上。我不知道为什么会发生这种情况。

如果我加载另外 40 个并再次在 IsCategoryCurrent 上更改属性,则第三批中的图片将设置 3 次。

最佳答案

我设法修复了它:

<Image 
   Grid.RowSpan="2"
   Name="MovieThumbnail" 
   Stretch="Fill"
   Width="130" Height="195"
   HorizontalAlignment="Center"
   VerticalAlignment="Center">
<i:Interaction.Triggers>
    <ei:DataTrigger Binding="{Binding DataContext.IsCategoryCurrent,ElementName=LayoutRoot}"
                    Value="true">
        <ei:ChangePropertyAction TargetObject="{Binding ElementName=MovieThumbnail}"
                                 TargetName="Source"
                                 PropertyName="Source">
            <ei:ChangePropertyAction.Value>
                <BitmapImage CreateOptions="BackgroundCreation"
                             UriSource="{Binding Path=Image120x170}"/>
            </ei:ChangePropertyAction.Value>
        </ei:ChangePropertyAction>
    </ei:DataTrigger>
    <ei:DataTrigger Binding="{Binding DataContext.IsCategoryCurrent,ElementName=LayoutRoot}"
                    Value="false">
        <ei:ChangePropertyAction TargetObject="{Binding ElementName=MovieThumbnail}"
                                 TargetName="Source"
                                 Value="{x:Null}"
                                 PropertyName="Source"/>
    </ei:DataTrigger>
</i:Interaction.Triggers>
</Image>

每次更改时,我都会引发 IsCategoryCurrent 的属性更改事件。

关于image - LongListSelector 项模板中图像控件的 ChangePropertyAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18332835/

相关文章:

node.js - 使用 Node.js Sequelize 和 Hooks 实现触发器

c# - Firebase:在 Windows Phone 上使用 Accept: text/event-stream

c# - Windows Phone 8 无法第二次调用 AudioVideoCaptureDevice

mysql触发器对列ID等于最后插入的行ID和存储的列求和

apache - 安装.deb后触发apache重新启动的好方法是什么?

c# - 适用于多种屏幕尺寸的 Windows Phone 8.1 字体和图像

html - CSS悬停在特定位置显示文本

laravel - 如果使用VUE JS在s3中不存在图像,如何设置默认图像

image - TImageViewer中,如何获取用户点击图片的位置?

image - 视差效果 | flutter 中的可滚动背景图像