Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将属性绑定到listboxitem模板中定义的控件_C#_Silverlight_Visual Studio 2010 - Fatal编程技术网

C# 将属性绑定到listboxitem模板中定义的控件

C# 将属性绑定到listboxitem模板中定义的控件,c#,silverlight,visual-studio-2010,C#,Silverlight,Visual Studio 2010,我有一门课叫ledgerObject: public class LedgerObject { public ChargeLine ChargeLine{ get; set; } public DelegateCommand Click_hyperbnCommand{ get; private set; } public LedgerObject() { this.Click_hyperbnCommand = new DelegateComma

我有一门课叫ledgerObject:

public class LedgerObject
{
    public ChargeLine ChargeLine{ get; set; }

    public DelegateCommand Click_hyperbnCommand{ get; private set; }

    public LedgerObject()
    {
        this.Click_hyperbnCommand = new DelegateCommand(click_btn);
    }

    private void click_btn(object args)
    {
    }
}
作为此类属性的chargeLine本身就是一个类,其中包含一些属性

因此,我将listbox的datacontext绑定到一个LedgerObject数组,并将listboxitem模板中定义的textblock控件绑定到ChargeLine的属性。任何想法或建议都会有帮助

我尝试过这个,但没有成功:

<TextBlock Margin="4 0 4 0" Grid.Column="3" Text="{Binding Path=ChargeLine.SimCode}" TextDecorations="Underline" Foreground="Red" />

您必须使用列表框的
ItemsSource
-属性,而不是
DataContext

//编辑


对原因进行了更详细的解释

你试过的代码丢失了。我的答案基本上是你已经尝试过的。“不工作”是什么意思?我在列表框中看不到任何结果。。我调试过,datacontext有数据,但没有显示在listbox中。啊!真正的问题隐藏在他的问题文本中!打得好+1.嗨,gammelgul,它起作用了,但是你能解释一下为什么它不适用于数据上下文吗。