// MyClass.cs
namespace SimpleBinding
{
class MyClass
{
private string name; public string Name
{
get { return name; }
set { name = value; }
}
private int age; public int Age
{
get { return age; }
set { age = value; }
}
}
}// Window1.xaml
<Window x:Class="SimpleBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sb="clr-namespace:SimpleBinding"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.Resources>
<sb:MyClass x:Key="MyKey" Name="AdoDotNet" Age="20" />
</Grid.Resources>
<Grid.DataContext>
<Binding Source="{StaticResource MyKey}" />
</Grid.DataContext>
...这种情况下怎样从代码访问通过xmal初始化的这个对象?
namespace SimpleBinding
{
class MyClass
{
private string name; public string Name
{
get { return name; }
set { name = value; }
}
private int age; public int Age
{
get { return age; }
set { age = value; }
}
}
}// Window1.xaml
<Window x:Class="SimpleBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sb="clr-namespace:SimpleBinding"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.Resources>
<sb:MyClass x:Key="MyKey" Name="AdoDotNet" Age="20" />
</Grid.Resources>
<Grid.DataContext>
<Binding Source="{StaticResource MyKey}" />
</Grid.DataContext>
...这种情况下怎样从代码访问通过xmal初始化的这个对象?
解决方案 »
- C# 通讯 心跳包问题
- 如何定义DataGridView只显示特定的项
- 在上传word时把他转换为html文件并保存在本地,请问怎么获取保存后的html并通过上传控件上传到服务器上?
- Visual Studio2005自带SqlServer2005操作问题
- 问DataTable.Select()到底返回一个什么样的数组..
- Ext.Viewport的item里的加载顺序
- 请问如何在C#中真正删除DBF文件中的记录。现在我只能作一个删除标识。急呀,高分请教了
- 用C#编写的小程序,向数据库写数据时出现的错误
- 想将Word的Doc文件内容显示在Web页面中,不知这事会不会很难,如果能,请详细给在下讲解
- 如何得到datagrid中,某列的列名?
- 怎么将可变的数组的值赋给TEXTBOX,用到TEXTBOX的个数跟数组的维数一样,,
- 如何将一个“非托管的函数”作为一个托管代码中的“委托”来使用???
// cls.Name, cls.Age
MyClass cls = myGrid.DataContext as MyClass;