小编and*_*y_t的帖子

在构造函数中设置 DataContext=this 和在 WPF 中绑定到 {RelativeSource Self} 之间的区别?

下一个代码按预期工作:

询问窗口.xaml:

<Window
    x:Class='AskWPF.AskWindow'
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
    >

<DataGrid ItemsSource="{Binding SimpleItems}" />

</Window>
Run Code Online (Sandbox Code Playgroud)

AskWindow.xaml.cs:

namespace AskWPF {

public class SimpleRow {
    private string firstColumn;
    private string secondColumn;

    public SimpleRow(string first, string second) {
        firstColumn = first;
        secondColumn = second;
    }

    public string FirstColumn {
        get { return firstColumn; }
        set { firstColumn = value; }
    }

    public string SecondColumn {
        get { return secondColumn; }
        set { secondColumn = value; }
    }
}

public partial class AskWindow : Window {

    private …
Run Code Online (Sandbox Code Playgroud)

c# wpf datacontext xaml relativesource

5
推荐指数
1
解决办法
9686
查看次数

标签 统计

c# ×1

datacontext ×1

relativesource ×1

wpf ×1

xaml ×1