Wpf用xaml发布绑定代码 [英] Wpf issue binding code behind with xaml
本文介绍了Wpf用xaml发布绑定代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在WPF页面上显示这是关于这背后的代码。请问有人能说出最佳方法吗?谢谢
I want to show this on WPF page about this is code behind. Please, can someone tell the best way to do it? Thank you
<pre> public partial class About : Page
{
public About()
{
InitializeComponent();
//About.Title = String.Format("About {0}", AssemblyTitle);
//string Title = String.Format("About {0}", AssemblyTitle);
//this.lblTitle.Text = String.Format("About {0}", AssemblyVersion);
}
#region Assembly Attribute Accessors
public string AssemblyTitle
{
get
{
object[] attrinbutes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if(attrinbutes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attrinbutes[0];
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion
}
我有什么试过:
堆栈和其他互联网东西
What I have tried:
Stack and other internet things
推荐答案
只需设置DataContext页面自身(DataContext = this;),在页面的XAML中使用{Binding AssemblyCopyright}等。什么是行不通的是双向绑定,但似乎你不想编辑这些字段。所以你可以在几秒钟内完成这项工作。
just set the DataContext of the Page to itself (DataContext = this;), Use {Binding AssemblyCopyright} etc. in the page's XAML. What won't work is a two-way binding but it seems you don't want to edit these fields anyway. So you can get this to work in seconds.
这篇关于Wpf用xaml发布绑定代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文