我工作的一个数字标牌WPF应用程序和基础结构的设置如下:WPF MVVM的DataTemplates - 景观更新
我有一个网格,它绑定到一个播放列表对象的单一视图。播放列表包含窗格,窗格包含播放列表项目,播放列表项目每个都包含一个内容项目。我使用DataTemplates为每件作品建立视图,例如
<!-- This template represents a single content pane, no real display here, just empty space with a height and width -->
<DataTemplate DataType="{x:Type entities:ContentPane}">
<ContentControl
Content="{Binding CurrentPlaylistItem, Mode=OneWay}"
Height="{Binding Height, Mode=OneTime}"
Width="{Binding Width, Mode=OneTime}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
/>
</DataTemplate>
<!-- This is a playlist item which is contained within a ContentPane.
This also has no real display, just a placeholder for the content item, and will likely contain some transition information-->
<DataTemplate DataType="{x:Type entities:PlaylistItem}">
<inf:TransitionableContentControl Content="{Binding ContentItem}"></inf:TransitionableContentControl>
</DataTemplate>
<!-- image item template
the path can be any valid uri e.g. http://... or file://... -->
<DataTemplate DataType="{x:Type contentTypes:ImageContentType}">
<Grid Background="Transparent" x:Name="ImageType">
<Image Source="{Binding Bitmap, Mode=OneTime}"></Image>
<inf:BusinessAd
ContainerHeight="{Binding ImageHeight, Mode=OneTime}"
ContainerWidth="{Binding ImageWidth, Mode=OneTime}"
Visibility="{Binding AdText, Converter={StaticResource _VisibilityConverter}, Mode=OneWay}"
Text="{Binding AdText.Text, Mode=OneTime}"
AdFontSize="{Binding AdText.TextStyle.FontSize}"
AdFontFamily="{Binding AdText.TextStyle.FontFamily}">
<ContentControl
Content="{Binding AdText, Mode=OneTime}"
ContentTemplate="{StaticResource BusinessAdTextTemplate}">
</ContentControl>
</inf:BusinessAd>
</Grid>
</DataTemplate>
随着datacontext的更改,每个窗格中的内容会从一个项目转换到下一个项目。我遇到了一个问题,用户在同一个窗格中连续放置两个相同的项目,无论是视频,图像等。发生的变化是未检测到更改,UI不更新。在视频的情况下,它冻结在第一个视频的最后一帧,整个应用程序挂起。
我曾尝试PlaylistItem类中做一个OnPropertyChanged(“ContentItem”),尝试设置共享我的数据模板=“false”时,我尝试了ContentItem对象上更改属性和提高的PropertyChanged事件,似乎没有任何工作。我打开了数据绑定的跟踪,看看发生了什么,它看起来似乎正常工作。当我更改ContentItem上的属性时,它会为新项目显示一个新的散列,但在UI上不会更改。
内TransitionableContentControl在PlaylistItem,从一个内容项去同一个时OnContentChanged倍率从不打。如果我将该控件与常规ContentControl交换,则不会更改。
您是否尝试将模式从'OneTime'改为'OneWay'? –
是的,没有任何效果 –
如果你能以某种方式提供再现问题的样本项目,我将很乐意进一步调查此。 – Stipo