怎么样调用 Silverlight 客户端 APIs

介绍

Microsoft Silverlight 插件 支持 一个扩展的编程模型,这包括 托管 和非托管 代码. 非托管 APIs 在 Silverlight 1.0 (formerly WPF/E) Beta release是有效的,同样也存在于Silverlight 1.1 Alpha (May 2007) release. 而 托管 APIs 是在 Silverlight 1.1 Alpha (May 2007) release才支持的. 你可以使用CLR调用 托管 APIs,这个特性也是在新版本的VS也就是 Visual Studio Code Name "Orcas."中将要集成的,目前,C# 和 Visual Basic 是可以在1.1中使用的.你也可以使用 dynamic language runtime (DLR). 更多关于 DLR,请查看 怎么样使用动态语言来开发 Silverlight .

详细的介绍 Siverlight 托管 API 目前不能提供. 然而,你可以使用一些反射工具来查看 托管 程序集而来了解有些什么 APIs 是可以调用的. 有关此项详细消息,请查看 怎么样使用Visual Studio Object Browser浏览Silverlight 程序集.

在本篇我们将介绍一些你在开发基于Silverlight的 应用程序的一些常用的使用托管代码的APIs . 在大多数情况下,对于object model而言,托管 API 一般与对语法和出现的位置都比较严格,这和 非托管 API是一样的. 因此,你甚至可以在非托管 代码的基础上来进行 托管代码的开发. 然而,因为object model或命名方式的不一致,这种等价还是需要商榷的.

Silverlight 托管 类库的 层次

很多的托管类依靠Silverlight control 和其UI 特性进行编程,它们都是遵循这些层次关系的:

依赖对象

  • UIElement

    • FrameworkElement

如果你曾经有过Windows Presentation Foundation (WPF)开发基础,那么你就会对这里的层次关系感到熟悉. 然而,却不像WPF中表面一样,当在开发 Silverlight程序时,你将自己总结和体会对每个类所充当的在层次关系中的角色. 在Silverlight 中你可以这样认为: FrameworkElement 类是基础 "element" 类,它们包含了很多你在XAML中定义或UI中定义的元素的有用的 APIs.

但是这不代表所有你在 XAML中例示的元素都是 FrameworkElement. 这里有许多元素,它们起了给其它一些UI元素的某些属性赋值的作用,但是这些属性可能会被精心的包装过. 我们举一个确切的例子,AnimationStoryboard的派生类,它们都不是 FrameworkElement 对象. 事实上,animations Storyboard 经常用来控制一些UI 元素.

浏览 Object Tree 并且 找到已经命名的Objects

一个独立的XAML页的object tree一般都是以一个 XAML root element开始的. 当前存在的 object tree 假设 XAML 页 已经是 Silverlight control的源并且已经解析成功了 . (当然也可以直接创建一个作为resources的 XAML 文件,或者直接将其载入到object tree中,在这种状况下object tree加入到XAML的 root 里来.)

对于 托管代码,当你为XAML root定义了一个 x:Class,这样你就可以轻松的得到XAML root的引用: 你可以直接在后台敲入 "this" 或 "Me". 然而,某一个object的object tree中的属性并不是都可以引用到的,比如它的构造函数. 如果构造函数被调用,在这种情况下,object tree的大部分还没有构造出来; 你必须等到XAML被解析了.

对于根结点前的一些object对象,你有三种方法来使用它们,其中有两点是有密切关系的.

  • 你可以顺着object tree的root一直往下,使用关相的 内容模型所提供的属性来得到所需要的对象引用,比如 Panel.Children,或使用泛型集合索引. 这种方法可能并不是你最好的选择,因为这需要你对XAML文件的结构非常的熟悉. 这通常只是用来进入内容模型,奇怪的是,目前确没有单个的 API 是提供这项功能的. 一般的,你可能只是使用这种方法来进入内容模型或集合的的某一个层次而已.

  • 你可以给XAML element敲入一个 x:Name属性 . 然后你就可以使用DependencyObject.FindName这个API来得到该对象的引用了.(DependencyObject 是一个很基础的类,所以你几乎可以在所有的Element中找到这个API.) 如果你使用过 非托管 APIs 来开发过 Microsoft Silverlight 1.0 (formerly WPF/E),那这个方法你可能就会比较熟悉了. FindName 返回一个类型的 Object,但FindName 有一个不太方便的就是你必须指定它返回的类型,这样你才能正确有使用它. 这意味你必须了解当前方法所返回的正确的类型.

    CS

    //using 'this' against the root where this x:Class applies
    //in this case we know that we are trying to find a TextBlock and can cast
    TextBlock tb = this.FindName("myTextBlock") as TextBlock;
    
    

    VB

    'using 'this' against the root where this x:Class applies
    'in this case we know that we are trying to find a TextBlock and can cast
    Dim tb As TextBlock = CType(Me.FindName("myTextBlock"),TextBlock)
    
    
  • 只要你使用Visual Studio Code Name "Orcas" 和其提供 Silverlight 模板,并使用它的 build过程,这你就可以有一个更好选择了. 给你的Element一个x:Name 属性. 这样,你可以不用一定要使用 FindName了,考虑到 x:Name 其实是和后台的相对应的类是引用关系. 打个比方,如果你创建了一个element <TextBlock x:Name="myTextBlock"/>,并且你编程的对象是 x:Class,这样,你只需要要简单的敲入 myTextBlock 就可以得到引用了,然后你敲入一个点,相对应的属性,方法或者事件处理事件就能出来了. 通过IntelliSense你可以浏览对象所提供的所有可供调用的内容. 每次生成后台代码的过程可以确保这些自动引用的正确添加. 这个生成的代码文件其实是x:Class的一个partial类,它们将在使用的时候一起编译 . 你可以查看Silverlight project的编译机制: x:Class的partial class定义,XAML root中的 Loaded handler 其实会调用后台文件的 InitializeComponent,和在obj 目录中生成的文件 (它重定义了 InitializeComponent 以此来在每次加载时,能正确的提供这种引用关系). 你可以发现当你加入一个已经命名的element到 XAML文件中来,你可能需要预编译,这样才能得到相应的有着最新对象名的 IntelliSense .

  • 生成的后台代码和其引用都是能简单获得的,但你应该注意,你并不是时刻都能有效的使用它的. 比如,当你想进行 Silverlight control 合并,你会发现后台文件和XAML文件的关系似乎是反着的,XAML文件总要比后台文件慢一点. 因此,你可能会觉得在创建自定义控件时使用 FindName 要更频繁一些.

从object tree 向 root element方向遍历,你可以用 API FrameworkElement.Parent. 当到达 root时,FrameworkElement.Parent将返回 null.

获取或设置一些附加属性

附加属性是XAML 语言定义的,以此来说明怎么样给 elements 的各种特殊属性赋值,甚至这个属性并不存在于当前element的成员列表中. 举附加属性的一个例子,在 Silverlight 客户端有一个 API 由三个 Canvas 属性组成,他们可以定位Canvas的子elements的呈现外观. 他们是 Canvas.Left,Canvas.Top,和 Canvas.ZIndex. 当你想在XAML文件中进行这些属性的设置的时候,你必须以 Canvas owner的类型来限定并以Owner.Property 形式来调用,注意,你不要直接在 Canvas中来设置该属性. 相反,你应该在 Canvas的直接子对象中来设置,父对象 Canvas 会读入这些属性信息,来控制子对象的呈现效果.

因为附加属性的特殊性,在托管代码中,你不能使用 Object.Property 形式来给其赋值,因为这总有两个对象在使用 (一个是 XAML 中的对象本身,还有一个是在属性被设置的时候的对象的实例).

在 托管 代码中,你可以通过调用DependencyObject.GetValue来得到 附加属性值 .第一个参数是指属性的从属者,它是后台类中的一个成员.你可以通过 DependencyObject.SetValue来设置属性值. 第一个参数同样是指属性的从属者,第二个是要设置的值. 在每个示例中,都是使用的实例方法,它们的调用都依靠实例所提供的可以设置的附加属性.

CS

//myTextBlock is a TextBlock from XAML,which is child of a Canvas
double currentLeft = (double) myTextBlock.GetValue(Canvas.LeftProperty);
if (currentLeft > 400.0) { myTextBlock.SetValue(Canvas.LeftProperty,400); }

VB

'myTextBlock is a TextBlock from XAML,which is child of a Canvas
Dim currentLeft As Double = CType(myTextBlock.GetValue(Canvas.LeftProperty),Double)
If (currentLeft > 400.0) Then
    myTextBlock.SetValue(Canvas.LeftProperty,400)
End If

GetValueSetValue 其实有很广的用处.对于 Silverlight client,只要对象提供了相应的属性,你就可以通过这两个方法来取得或者设置它们的值.例如,你可以调用 myTextBlock.SetValue(TextBlock.TextProperty "hello"). 但是在这些示例中,并没有 "regular" (非附加) 属性,然而 Instance.Property 形式对于设置或获取属性取来说还是要更直观一些.

高和宽

HeightWidth 存在于 FrameworkElement. 你可以设置 HeightWidthCanvas,TextBlock 和各种 Shape 基础类上.

有一小部分的elements (比如 TextBlock) 还存在一个 ActualWidthActualHeight 属性. 它们是在实际情况下被计算出来的,只读的属性. ActualWidthActualHeight将受到多种因素的影响而改变,这将帮助你得到实际上显示出来的尺寸. 比如,当你的 TextBlock里包含一些文字,文字的大小受 FontSize,FontFamily,FontSpacing,等的影响,当然,TextBlock 的实际展示大小也会受这些因素的影响了.

注意

HeightWidth 对于自定义控件,目前还需要有一个工作区来配合使用,这取决于你如何使用基础的属性. 想查看详细说明,点击 怎么样创建一个自定义的 Silverlight Controls.

TextBlock and Text APIs

The TextBlock class 包括 a number of APIs. There is a very limited text object model (exposed through the Inlines collection),and there are several expected text-related properties for text in UI:

  • FontFamily: Set as a string that names the font family. Silverlight initially supports only a few fonts (see the 非托管 documentation for TextBlock for details). You can download fonts other than the initial fonts by calling TextBlock.SetFontSource.

  • FontSize: Set in pixels.

  • FontStretch: Uses the FontStretches enumeration. Check the enumeration values in the object browser,or see the Silverlight 1.0 beta documentation for details.

  • FontStyle: A value of the FontStyles enumeration,Normal,or Italic.

  • FontWeight: Uses the FontWeights enumeration. Check the enumeration values in the object browser,or see the 非托管 Silverlight documentation for more details.

  • Foreground: Typically,a solid color declared by XAML attribute,but it can also be set to any class derived from Brush (for example,an ImageBrush or GradientBrush) for special effects.

  • TextDecorations: A value of the TextDecorations enumeration,None,or Underline.

  • TextWrapping: A value of the TextWrapping enumeration,NoWrap,or Wrap.

  • Text

CS

TextBlock tb = new TextBlock();
tb.FontFamily = "Arial";  //one of the initial fonts
tb.FontSize = 20;
tb.FontStretch = FontStretches.SemiExpanded;
tb.FontStyle = FontStyles.Italic;
tb.FontWeight = FontWeights.DemiBold;
SolidColorBrush golden = new SolidColorBrush();
golden.Color = Color.FromRgb(211,147,12);
tb.Foreground = golden;
tb.TextDecorations = TextDecorations.Underline;
tb.TextWrapping = TextWrapping.Wrap;
tb.Text = "I am nondefault!";
Run il = new Run();
il.FontSize = 40;
il.Text = "Hello!";
tb.Inlines.Insert(0,il);

VB

Dim tb As TextBlock = New TextBlock()
tb.FontFamily = "Arial"  'one of the initial fonts
tb.FontSize = 20
tb.FontStretch = FontStretches.SemiExpanded
tb.FontStyle = FontStyles.Italic
tb.FontWeight = FontWeights.DemiBold
Dim golden As SolidColorBrush = New SolidColorBrush()
golden.Color = Color.FromRgb(211,12)
tb.Foreground = golden
tb.TextDecorations = TextDecorations.Underline
tb.TextWrapping = TextWrapping.Wrap
tb.Text = "I am nondefault!"
Dim il As Run = New Run()
il.FontSize = 40
il.Text = "Hello!"
tb.Inlines.Insert(0,il)

Colors and Brushes

When set in XAML as an attribute value,you can specify solid colors with approximately 256 named color values based on UNIX X11,including intriguing colors such as "MistyRose" and "PapayaWhip". Or,you can specify RGB or ARGB values by preceding the string value with a hash sign (#). In the Silverlight 托管 API,the number of predefined colors available is smaller; it is limited to 16 colors. Therefore,the primary mechanism for defining a solid color is to call the static Color.FromArgb,Color.FromScRgb,or Color.FromRgb method. Also,the various classes derived from Brush (such as SolidColorBrush) have only the default constructor. They do not have any convenience constructors. You must then set the relevant properties individually after construction. For classes such as RadialGradientBrush you must also construct each GradientStop and add to the GradientCollection.

CS

Rectangle r = new Rectangle();
r.Width = 400;
r.Height = 300;
SolidColorBrush golden = new SolidColorBrush();
golden.Color = Color.FromRgb(211,12);
r.Fill = golden;

VB

Dim r As Rectangle = New Rectangle()
r.Width = 400
r.Height = 300
Dim golden As SolidColorBrush = New SolidColorBrush()
golden.Color = Color.FromRgb(211,12)
r.Fill = golden

A large amount of routine code can be required,especially to produce brushes and to handle the potential for reusing a brush. The following development strategy will be helpful when a brush gets significantly complex:

  1. Define the brush as a XAML file,or even as a string in valid XAML form (including the xmlns at the root).

  2. Include that string or file as an embedded resource for your application.

  3. Access the resource as a stream,and use the stream as a string source for the XamlReader.Load API (more about this API in an upcoming section).

  4. Cast the result to the appropriate Brush class,and use it to set your property.

One advantage of this approach is that you can use design tools such as Microsoft Expression Blend to produce the XAML,which will yield satisfying results more quickly than iterating on ARGB values in code or pasting strings from other design tools. The Silverlight 托管 APIs do not yet have a resources system that is quite as developed as the ResourceDictionary-based resources system for WPF,but embedded resources can serve the purpose.

Mouse and Mouse Position

Browser client APIs can be used to get mouse positions in the overall browser,but that is usually not adequate for 基于Silverlight的 applications. Instead of using a service that constantly monitors the mouse input device (which is the case for WPF) the mouse position is reported only in response to mouse events. 然而,one of these events is MouseMove,which fires frequently. Even if the mouse never moves,you can get an initial mouse position when the MouseEnter event for the main Canvas fires as the Canvas is loaded (so long as the mouse started over the client area). You obtain the mouse pointer position by calling the method MouseEventArgs.GetPosition from the event data instance,instead of using directly-defined X and Y properties. This method takes a parameter of type UIElement; the element you provide to the method will be used to calculate a position offset. If you pass null,the coordinate system is relative to the Silverlight control content area. Otherwise,the typical element to pass to the GetPosition input parameter if you do not pass null is the event sender (which you will need to cast to UIElement). You can pass any element,including elements not clicked upon by strict hit-testing definition,which might mean that the X and Y values you get from GetPosition are negative.

CS

void el_MouseClick(object sender,MouseEventArgs e) {
    //sender is a 200px ellipse,the closer you click to its relative center,the more it disappears
    Ellipse el = sender as Ellipse;
    double x = e.GetPosition(el).X;
    el.Opacity = Math.Abs(x - 100)/100;
}

VB

Sub el_MouseClick(ByVal sender As Object,ByVal e As MouseEventArgs) Handles HotMouse.MouseLeftButtonUp
    'sender is a 200px ellipse,the more it disappears
    Dim el As Ellipse = CType(sender,Ellipse)
    Dim x As Double = e.GetPosition(el).X
    el.Opacity = Math.Abs(x - 100) / 100
End Sub

The two most common scenarios for getting the mouse position are to determine where the mouse was when a button was clicked,and to determine where the mouse is when crossing a boundary. Both of these scenarios are involved in a drag-and-drop scenario as well.

XamlReader

In JavaScript,there are no constructors,so you cannot create a new instance of an element you want to add to a tree. You can use DHTML-like strategies such as having parallel trees that are already constructed and using a hide-show approach,you can use animations (but only to change properties,not add to the tree),or you need to call Control.content.createFromXAML to effectively use the parser as a constructor engine. For this reason,you may have found yourself calling createFromXAML fairly frequently in Silverlight 1.0 if you were creating a particularly dynamic UI.

In 托管 code,you have access to constructors. Therefore,in many cases,calling XamlReader.Load (which is the 托管 createFromXaml equivalent) is unnecessary,particularly because you are already working in a code model and calling a constructor is not difficult. The constructor approach,combined with setting properties on the newly constructed instances and adding them to the existing object tree,works well if the run-time design changes are simple.

On the other hand,if the design changes were complex,and you had a designer-coder responsibility split where the designer produced two different UIs for each state,it might make sense to load from XAML to refresh the UI. 然而,in this case,you really should not load XAML from a string directly,as the XamlReader.Load signature might indicate. Instead,it is better code style to obtain the string from a stored resource or a separate file,perhaps using System.IO.StreamReader,so that the XAML handoff from designer to coder will consist of a file rather than strings.

CS

Assembly assembly = this.GetType().Assembly;
//BigBrush.xaml is a LinearGradientBrush with half a dozen stops
//and perhaps it gets used frequently,from different files
Stream s = assembly.GetManifestResourceStream("CallClientAPIs.BigBrush.xaml");
StreamReader sr = new StreamReader(s);
Brush b = (Brush)XamlReader.Load(sr.ReadToEnd());
sr.Close();

VB

Dim assembly As Assembly = Me.GetType().Assembly
'BigBrush.xaml is a LinearGradientBrush with half a dozen stops
'and perhaps it gets used frequently,from different files
Dim s As Stream = assembly.GetManifestResourceStream("CallClientAPIsVB.BigBrush.xaml")
Dim sr As StreamReader = New StreamReader(s)
Dim b As Brush = CType(XamlReader.Load(sr.ReadToEnd()),Brush)
sr.Close()

For both the JavaScript createFromXAML and XamlReader.Load methods,you should also consider that APIs that take markup as strings can actively fight the UI-designing capabilities of whatever design tool is used to define the UI markup,if you use those APIs indiscriminately.

Downloader

In 托管 code,you can create the Downloader object directly using its constructor (in 非托管 code,you had to call Control.createObject to get it from the Silverlight control).

After you construct Downloader,you typically attach handlers to one or more of the DownloadProgress,DownloadFailed,or Completed events. After that,you call Open,passing the Uniform Resource Identifier (URI) of the content to download. Finally,you call Send to initiate the request.

note

If you are handling download progress,make sure to set the async parameter to true when you call Downloader.Open.

Getting Events and Information from the Hosting Browser

You can access the HTML DOM for the document contained in the browser,and get quite a bit of information that way (see How to: Access the HTML DOM from 托管 Code). 然而,there is one particular set of information that is difficult to obtain that way: the size of the hosting browser window (minus toolbars,edges and chrome),and when the user changes that size. A quick way to get that information is to handle the events of the BrowserHost class,which exists in the System.Windows.Interop namespace. At any time,you can check the values of the BrowserHost.ActualWidth and BrowserHost.ActualHeight properties. You can also write handlers for the Resize or FullScreenChange event so that you know specifically when the ActualWidth or ActualHeight changes,and which user action (resize or toggle fullscreen) caused the change.

Rectangle and Rect

Silverlight has two similarly named types: the Rectangle class,which is in the namespace System.Windows.Shapes,and the Rect structure,which is in System.Windows. The Rectangle class is a UI element that you can place on a page to fill an area with a particular color or brush. The Rect structure is not a UI element; it is a structure that is used as a value for other types of objects that are generally rectangular,and it may or may not have an immediate visual representation. For example,Rect describes a RectangleGeometry or the bounds of an ink Stroke. Rect 包括 several utility methods so that you can compare Rect instances,or adjust values of an existing Rect.

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的IsEnabled=“{BindingABC}”,但这不起作用–MenuItem总是启用.提前感谢您的线索!干杯编辑:有趣的是,当设置Mode=TwoWay时,绑定似乎有效.但是,在菜单项上移动鼠标后,将更新上下文菜单的外观.这是异步工作吗?右键
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,因为我确信即使是一个c#人也可以使用类似的.net实现来回答这个问题).我申请的简短说明:我的桌面应用程序将仅在win平台上运行,使用vb.net,它是一个简单的网吧管理软件,在服务器上运行服务器gui,在工作站上运行客户端gui,
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如果它在UIThread上,如何将文件请求和ProcessFile()移动到单独的线程?varxClient=newServiceReference1.Service1SoapClient();xClient.Retrieve_File_Completed+=newEventHandler<ServiceReference1.Retrieve_Fi
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不在办公室使用sharepoint.所以不知道如何开始.这些是我的新手问题>学习共享点值得努力吗?>学习sharepoint的资源在哪里?>我是否应该考虑开发哪些参考项目?感谢您的意见.解决方法:SharePoint以如此积极的方式改变了我的职业
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:Thecollectiondatacontracttype‘System.Collections.Generic.Listcannotbedeserializedbecauseitdoesnothaveapublicparameterlessconstructor.Addingapublicparameterlessconstructorwillf
我需要根据Silverlight中的某些配置值设置给定控件的Style.我想有可能从两种可用的样式(静态资源)中选择一个控件样式.我试图做一些像:<TextBoxStyle="{BindingABC}"/>哪里publicstringABC{get{return"{StaticResourceMyStyle}";}}不幸的是,这不起作用.你有
我刚买了第一台Android设备,我喜欢它…我也很喜欢你可以创建自己的应用程序并随意分发它们.我已经阅读了一些关于Monodroid的内容,而且显然微软希望将Silverlight放在这些设备上,尽管没有太多关于它们的信息……但是Moonlight呢?如果Monodroid就像Mono……为什么我们需要它呢?相反
我们的ASP.NET网站允许用户执行各种查询,并根据从数据库查询的结果显示网络图(如UML图).目前,我们正在生成一个位图并显示它.但由于我们需要支持允许用户以交互方式显示/隐藏某些块的功能,因此我们计划使用Silverlight来渲染图形.我们还计划在未来添加更多互动.我有两个问题:>ASP
我正在开发一个Silverlight4应用程序,我已经创建了一个自定义的启动画面.乍一看,自定义启动画面运行良好–非常好.几天后,我开始注意到闪屏不再显示,屏幕仍然是空白.这似乎只发生在我打开多个指向同一个应用程序的IE选项卡/窗口时.前几个将加载正常,而以下选项卡/窗口将保持“白
这是我的XAML:<ImageVerticalAlignment="Center"HorizontalAlignment="Center"Source="{BindingInput,Converter={StaticResourceByteArrayToBitmapConverter}}"><Image.Rend
问候,我有一个ItemsControl,我更改了模板,为绑定的ItemsSource中的每个对象显示一个RadioButton.但是ItemsSource可以为空,当它为空时我想显示默认值.像“绑定列表中没有可供您选择的项目”……我想到的一种方法是将ItemsControl.Visibility设置为Collapsed,并将TextBlock.Vsibi
堆栈溢出的第一个问题……我是C#的新手,但在学习它时却非常直接.几分钟前我才看到这个tutorial.通过各种c#技术阅读WCF,WPF,Silverlight,c#和asp.net,这是很多技术都可以用c#来实现.我将创建一个Web应用程序c#.我认为SilverLight似乎是我最好的选择.该应用程序将拥有一个数
我正在使用MVVM(Model-View-ViewModel)模式编写应用程序,并利用MicrosoftP&P团队的Prism和Unity位.我有一个包含项目列表的视图.这些项包含在ViewModel中的ObservableCollection中,View中的列表框是数据绑定的(ViewModel设置为View的DataContext).在ViewModel中,我有一个运行的
我有一个应用程序,它在首次运行时显示免责声明页面.选择“接受”或“拒绝”后,您再也看不到该页面了.但是,当您在第一次运行后按后退键尝试关闭应用程序时,您将返回免责声明页面,然后再次点击该页面,返回主页面,然后再次退出.这仅在应用程序第一次运行时发生,但我希望应用程序在
我正在尝试在SilverlightforWindowsPhone中使用异步HttpWebRequest.一切都很完美,直到我到达我应该打电话的地方privatestaticManualResetEventallDone=newManualResetEvent(false);...request.BeginGetResponse(newAsyncCallback(GetResponseCallback),request);a
嗨,我有两个Writablebitmap,一个来自jpg,另一个来自png,并使用此方法在循环中混合颜色:privatestaticColorMix(Colorfrom,Colorto,floatpercent){floatamountFrom=1.0f-percent;returnColor.FromArgb((byte)(from.A*amountFrom+to.A*perc
我需要开发一个程序,它包含一个图像(png),中心有一个洞.在这个图像下将有一个框架,我想点击图像的透明孔我可以点击框架内的按钮.我不知道是否有一种方法可以通过图像或其他方式传播点击.谢谢你的帮助解决方法:你在图像上将IsHitTestVisible设置为false,然后点击浏览.
我正在研究一个silverlight应用程序,我发现List没有Find扩展方法说,List<Something>list=newList<Something>(something);list.Remove(list.Find(e=>e.id==10));没有查找扩展方法我错过了什么?解决方法:它不包括在内以减小运行时的大小.建议您使用LINQ扩展,例如First
我试图弄清楚如何设置Path元素的Data属性来获得此类型的软角:alttexthttp://i42.tinypic.com/1rzu6w.jpg现在我只有这样的尖角:alttexthttp://i42.tinypic.com/2eeleah.jpg我尝试用椭圆玩,但我无法得到我想要的东西.谢谢最佳答案:路径的段具有IsSmoothJoin属性,默认为false.
问题我有一个在远程服务器上运行的restfulWeb服务.我已经制作了一个使用它的WP7应用程序,所以我知道它有效.我正在将应用程序移植到SilverlightWeb应用程序并遇到问题.我已经包含了代码的简化版本以及引发的错误.EndGetResponse方法抛出错误.随意询问更多信息.我一直在寻找解