1
 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();

}

但是当我运行它时,对象结果为空,因为在加载 lightswitch 屏幕之前调用了预定义的 Loaded silverlight 函数,当我在按钮单击结果上调用方法获取属性时,因为加载了 lightswitch 屏幕,所以结果不是 null。所以我的问题是如何在屏幕以某种方式加载后调用此方法(没有按钮单击)。

4

1 回答 1

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);
      });
    }
于 2013-04-02T13:34:44.900 回答