从静态扩展 XAML 中检索值 [英] Retrieving value from static extension XAML

查看:27
本文介绍了从静态扩展 XAML 中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从静态扩展中检索值 (Int32.MaxValue):

How do I retrieve the value (Int32.MaxValue) from the static extension:

    <x:Static
        x:Key="TooltipTimeout"
        Member="s:Int32.MaxValue"
        />

...

<blablalba TooltipService.ShowDuration="{StaticResource TooltipTimeout}"/> <-- 顺便说一下,这不起作用

<blablalba TooltipService.ShowDuration="{StaticResource TooltipTimeout}"/> <-- this does not work by the way

推荐答案

在WPF中,你可以直接访问静态成员,像这样,

In WPF, You can access static member directly, like this,

<TextBlock TooltipService.ShowDuration="{x:Static s:Int32.MaxValue}"/> 

但是,您不能在 Silverlight 中执行相同操作,因为它不起作用.在silveright中,您必须编写一个包装类,如下所示,

However, you cannot do the same in Silverlight, as it wouldn't work. In silveright, you've to write a wrapper class, like this,

public class StaticMemberAccess
{
      public int Int32Max { get { return Int32.MaxValue; } }
      //define other wrapper propeties here, to access static member of .Net or your classes
}

然后在 XAML 中执行此操作,

Then do this in XAML,

<UserControl.Resources>
   <local:StaticMemberAccess x:Key="SMA"/>
</UserControl.Resources>

<TextBlock TooltipService.ShowDuration="{Binding Source={StaticResource SMA}, Path=Int32Max}"/> 

.

这篇关于从静态扩展 XAML 中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆