[英]data binding in wpf using datacontext
I am trying to work out data binding in C# in a wpf application and I got struck. 我试图在WPF应用程序中使用C#进行数据绑定,但我被吓到了。 I have a program and I need to bind my project settings, which can be changed and are displayed in a UI.
我有一个程序,需要绑定我的项目设置,可以对其进行更改并显示在UI中。
UI: 用户界面:
<ListView Name="lsview">
<ListView.DataContext >
<Binding Source="projpro"/>
</ListView.DataContext>
<ListView.View>
<GridView>
<GridViewColumn>
<TextBox Width="150" Name="projid" Text="{Binding Path=pp.test}" />
</GridViewColumn>
<GridViewColumn>
<TextBox Width="150">wtf from xaml</TextBox>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Code: 码:
public MainWindow()
{
InitializeComponent();
displayImage(true);
projectProperties();
projpro pp = new projpro();
lsview.DataContext = pp;
}
class: 类:
class projpro
{
string a="check1";
public string test
{
get { return a ; }
set
{
a = "check2";
}
}
} }
The class projpro needs to be a list of several parameters. projpro类需要是几个参数的列表。 I want to know how to display it.
我想知道如何显示它。 I have set
path
to pp. and I want to display the value of test in the UI. 我已将
path
设置为pp。我想在UI中显示test的值。 I read some artcles on MSDN but still I am clear how to access the code from xaml. 我在MSDN上读过一些文章,但我仍然清楚如何从xaml访问代码。 The values are dynamic in the class.
这些值在类中是动态的。
please throw some light. 请给点灯。
Thanks a lot in advance. 非常感谢。
cheers 干杯
尝试在单元绑定上使用propertyName。
<TextBox Width="150" Name="projid" Text="{Binding Path=test}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.