【发布时间】:2010-12-14 21:19:10
【问题描述】:
我有一些在后面的代码中实例化的对象,例如,XAML 被称为 window.xaml 并且在 window.xaml.cs 中
protected Dictionary<string, myClass> myDictionary;
如何仅使用 XAML 标记将此对象绑定到例如列表视图?
更新:
(这正是我的测试代码):
<Window x:Class="QuizBee.Host.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding windowname}" Height="300" Width="300"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
</Grid>
</Window>
在代码隐藏中
public partial class Window1 : Window
{
public const string windowname = "ABCDEFG";
public Window1()
{
InitializeComponent();
}
}
假设标题应该变成“ABCDEFG”吧?但它最终什么也没显示。
【问题讨论】:
-
奇怪的是,如果我更改窗口的属性分配顺序,它就不起作用。如果我设置“Title”属性后跟“DataContext”属性,则不会发生绑定。谁能解释一下? schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft.com/winfx/2006/xaml" xmlns:local ="clr-namespace:INotifyPropertyTest" Height="350" Width="525" DataContext= "{Binding RelativeSource={RelativeSource self}}" Title="{Binding WindowName}" >