开发者

Retrieving value from static extension XAML

开发者 https://www.devze.com 2023-01-27 23:05 出处:网络
How do I retri开发者_运维百科eve the value (Int32.MaxValue) from the static extension: <x:Static

How do I retri开发者_运维百科eve the value (Int32.MaxValue) from the static extension:

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

...

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


Methinks you're doing something else wrong. Slap this in kaxaml:

<Page
 xmlns:sys="clr-namespace:System;assembly=mscorlib"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Page.Resources>
  <x:Static x:Key="Derp" Member="sys:Int32.MaxValue"/>
  </Page.Resources>
  <Grid>  
  <TextBlock 
    ToolTipService.ShowDuration="{StaticResource Derp}" 
    ToolTip="Derp" Text="Herp"  />
  </Grid>
</Page>

Mod tested, mother approved.

If I had to guess, I think you're not defining your xml namespace for Int32 correctly.


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

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

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
}

Then do this in XAML,

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

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

.


Try to bind to your resource by setting it as the Source of your binding:

{Binding Source={StaticResource TooltipTimeout}}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号