Binding to Resources in Silverlight/WPF

1. 对于静态资源,如下binding:


image

<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

aa4656eabf2851613210d9dab71e028e

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}}"  />

原文地址:https://www.cnblogs.com/cubean/p/2289948.html