您的位置:首页 > 其它

Binding to Resources in Silverlight/WPF

2011-12-16 11:33 387 查看
1. 对于静态资源,如下binding:






 

<UserControl.Resources>
<l:i18n x:Key="i18n" />
</UserControl.Resources>

<StackPanel x:Name="LayoutRoot" Orientation="Horizontal">
<TextBox />
<Button Content="{Binding Path=SearchButton, Source={StaticResource i18n}}" />
</StackPanel>


 

但对于自定义的资源,like





namespace ResourceProjectNamespace {


public class ApplicationStrings {




        internal ApplicationStrings() {

        }




        public static string BtnShow {

            get {

                return ResourceManager.GetString("BtnShow", resourceCulture);

            }

        }




}



}

如果按以上写,程序运行时会报错:No matching constructor found on type …

所以对这类资源的binding需要用以下方式:

 

2. 自定义资源的binding

xmlns:resources="clr-namespace:ResourceProjectNamespace"

<Button Content="{Binding Source={x:Static resources:ApplicationStrings.BtnShow}}"  />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: