I have control like this
<UserControl x:Class="VideoControl.VideoControl" Loaded="getProperty"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
</UserControl>
我有这样的方法
private void getProperty(object sender, RoutedEventArgs e) {
var objContext = (IContentItem)this.DataContext;
var Scrn = (Microsoft.LightSwitch.Client.IScreenObject)objContext.Screen;
var anonObject = Scrn.Details.Properties["VidContentItemRessourcesItem"].Value;
string result= anonObject.GetType().GetProperty("AssetPubLocator").GetValue(anonObject, null).ToString();
}
但是当我运行它时,对象结果为null因为预定义的加载的silverlight函数在加载lightswitch屏幕之前被调用,当我在按钮上调用方法获取属性时单击结果isnt null因为加载了lightswitch屏幕。所以我的问题是如何在以某种方式加载屏幕之后调用此方法(没有按钮点击)。
答案 0 :(得分:0)
好的,我解决了这个问题
// My control property
public MyControlType MyControl;
partial void MyEntity_Loaded(bool succeeded) {
this.SetDisplayNameFromEntity(this.MyEntity);
// Open in new Thread
Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() => {
this.FindControl("VideoControler").ControlAvailable += (s, e) => {
// Loading Control
MyControl = (e.Control as MyControlNamespace.MyControlType);
};
// Calling method in Control and sending property there :-)
MyControl.PropertiesLoaded(this.MyEntity.SomeString);
});
}