Binding to Resources in Silverlight/WPF
2011-12-16 11:33
387 查看
1. 对于静态资源,如下binding:
但对于自定义的资源,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}}" />
<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}}" />
相关文章推荐
- Tips: Save some typing when binding values to UI in WPF/Silverlight
- Binding Events to Methods in the Silverlight MVVM View Models
- Element to Element Binding in Silverlight
- Binding and styling text to a RichTextBox in WPF
- Binding to a dictionary in Silverlight with INotifyPropertyChanged
- Silverlight Tips[4]: How to convert bytes to image in WPF
- Binding and styling text to a RichTextBox in WPF
- Simple Path Data Resources that I Add to Every WPF and Silverlight Project
- Binding UI Events from View to commands in ViewModel in Silverlight 4(转)
- MVVM之旅-给任意的事件绑定命令(Adventures in MVVM – Binding Commands to ANY Event) .
- WebSphere Portal XMLAccess: discover different ways to refer resources in XML script
- How to Display DataSet in Silverlight DataGrid
- How to Embed Silverlight Content in HTML
- How to get data from Oracle DB in silverlight via WCF ?
- WPF/Silverlight2.0 Binding(数据绑定)机制详解
- Silverlight/wpf DataGrid TextBox 等控件内容 Binding 中日期格式 StringFormat
- How to use two-way data binding in Flex
- How to detect and avoid memory and resources leaks in .NET applications
- VS2010中调试Silverlight Applicatoin时出现Bug.
- VS2010中调试Silverlight Applicatoin时出现Unable to start debugging的Bug.