假设我们有以下代码:
MyGridViewColumn.xaml
<GridViewColumn x:Class="some_namespace.MyGridViewColumn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type GridViewColumn}}, Path=MyString, Mode=OneTime"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
MyGridViewColumn.xaml.cs
namespace some_namespace
{
public partial class MyGridViewColumn
{
public MyGridViewColumn()
{
MyString = "Hello!";
InitializeComponent();
}
public string MyString { get; set; }
}
}
这感觉还可以,但它不起作用。什么是与#34; MyString&#34;的正确绑定?