小编Rob*_*nft的帖子

将绑定从C#转换为XAML

我无法在XAML中使用此绑定。

在C#中进行绑定的工作原理是:

public partial class myControl : UserControl
{
    // get singleton instance
    InfoPool Info = InfoPool.Info;

    public myControl()
    {
        InitializeComponent();

        // Test Binding
        Binding bind = new Binding();
        bind.Source = this.Info;
        bind.Path = new PropertyPath("Time");
        txtInfoTime.SetBinding(TextBlock.TextProperty, bind);
    }
}
Run Code Online (Sandbox Code Playgroud)

在XAML中绑定不是:

<TextBlock x:Name="txtInfoTime" Text="{Binding Path=Time, Source=Info}" />
Run Code Online (Sandbox Code Playgroud)

路径和源相同,所以我的错误在哪里?

Thx罗布

c# wpf xaml binding

3
推荐指数
1
解决办法
1924
查看次数

标签 统计

binding ×1

c# ×1

wpf ×1

xaml ×1