开发者

WPF DataTemplates and Custom Classes to handle events

开发者 https://www.devze.com 2022-12-12 00:23 出处:网络
If I have a custom class called VideoMedia (which contains a standard Uri for the video path) and I have a DataTemplate that I use to create a Video Player like controls.

If I have a custom class called VideoMedia (which contains a standard Uri for the video path) and I have a DataTemplate that I use to create a Video Player like controls.

<DataTemplate DataType="{x:Type v:VideoMedia}">
    <MyLib:VideoPlayer/>开发者_如何学C
</DataTemplate>

(The VideoPlayer class extends UserControl and simply controls the playback of a Video file)

How do I add an event handler into the VideoMedia class, so that it can contain a sort of TimeStarted property? I need it at runtime so I can tell if the video is running.

I am storing an IDictionary<int, VideoMedia> collection that I iterate over each 2 seconds to tell if the videos are playing. Is there a better way of doing it?


If your VideoPlayer usercontrol built properly with a IsPlaying dependancy property in it. Just do a Binding to VideoMedia.IsPlaying to the VideoPlayer.IsPlaying and you are good to go.

<MyLib:VideoPlayer  IsPlayingDP="{Binding IsPlaying}" ... />
0

精彩评论

暂无评论...
验证码 换一张
取 消