简体   繁体   English

绑定元素WPF应用程序

[英]Binding element WPF application

I have this code. 我有这个代码。

<MediaElement x:Name="VideoControl" Width="Auto" Height ="{Binding altezza}"
   Source="intro.avi" LoadedBehavior="Manual" UnloadedBehavior="Stop">
</MediaElement>

In the .cs file I have this method .cs文件中我有这个方法

public int altezza{
   get { return 150; }
}

But it's not called from WPF element. 但它不是从WPF元素调用的。

How I can fix it? 我该怎么办呢?

Thanks you for your reply 谢谢你的回复

您必须将Datacontext设置为Codebehind文件:

DataContext="{Binding RelativeSource={RelativeSource Self}}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM