1 如果要获得的对象就是产生事件的对象,则最简单。正如QuickStarts中列举的那样
<TextBlock Text="click me"  FontSize="50"
MouseLeftButtonDown="changelocation" />
</Canvas>
{
sender["Canvas.Top"] = 70; }
2 如果要获得对象包含的子元素对象,则可使用findName方法
Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Transparent"
MouseLeftButtonDown="changeEllipseColor">
<TextBlock Text="click me"  FontSize="50"/>
<Ellipse x:Name="myEllipse"
Height="200" Width="200"
Canvas.Left="30" Canvas.Top="80"
Stroke="Black" StrokeThickness="10" Fill="LightBlue"/>
</Canvas>
{
sender.findName("myEllipse").Fill = "red";
}
但这个方法似乎只能通过父对象获取子对象,可能是我还没有完全搞对,欢迎指正。
3 如果要通过一个对象或的其他非子对象,可使用getHost()
function OnPlay(sender,arg)
{   
    var host = sender.getHost();
    var otherObj = host.content.findName('otherName');
}
4 如果连一个对象也没有,则先用document.getElementById()方法获得host对象。
 var host = document.getElementById(hostID');
 var  obj = host.content.findName('objID');
注意hostID是在CreateSilverlight函数中指定的
function createSilverlight()
{
 Silverlight.createObjectEx({
  source: "TextContent.aspx",
  parentElement: document.getElementById("SilverlightControlHost"),//不是这个
  id: "SilverlightControl",//就是这个
  properties: {
   width: "80%",
   height: "24",
   version: "1.1",
   enableHtmlAccess: "true"
  },
  events: {}
 });

相关文章:

  • 2022-12-23
  • 2021-07-14
  • 1970-01-01
  • 2021-05-10
  • 2021-11-23
  • 2022-01-08
  • 2021-08-16
  • 2022-03-05
猜你喜欢
  • 2021-10-18
  • 2022-01-17
  • 2021-06-02
  • 2021-04-28
  • 2021-11-27
  • 2021-12-19
  • 2021-06-26
相关资源
相似解决方案