The issue of ApplyTemplate

     The issue is that the ApplyTemplate method is not called in the order you are expecting.  This appears to be a known issue and there is a work-around.  If you manually call ApplyTemplate() in the Loaded event of your control, the template should be applied and the video should play.  I applied this work-around to your code along with a few other minor-tweaks and it worked correctly for me.

Also, as another suggestion, I would strongly suggest that you convert setSource to a dependency property.  You can read more about dependency properties here.

customControl.cs

public class customControl:Control
{
    private MediaElement _vidStage;

    public customControl()
    {
        this.DefaultStyleKey = typeof(customControl);
        this.Loaded += new RoutedEventHandler(customControl_Loaded);
    }

    void customControl_Loaded(object sender, RoutedEventArgs e)
    {
        this.ApplyTemplate();
    }

    public override void OnApplyTemplate()
    {
        _vidStage = base.GetTemplateChild("vidStage") as MediaElement;
    }

 ...

public Uri Source
{
    get
    {
        return _vidStage.Source;
    }
    set
    {
        if (_vidStage != null)
        {
            _vidStage.Source = value;
           //_vidStage.Play();
           // For some reason, the video wouldn't play using Play()
           // I set the AutoPlay to true and it worked.
           _vidStage.AutoPlay = true;
        }
    }
}

...

Page.xaml.cs

    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Page_Loaded); // Setting the source after loading...
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // Please note the added forward-slash and I have set the Build Action to "Content" for the hippo.wmv file.
            g.Source = new Uri("/hippo.wmv", UriKind.Relative);
        }

 ...

 I hope this helps!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值