I am trying to work out data binding in C# in a wpf application and I got struck. I have a program and I need to bind my project settings, which can be changed and are displayed in a 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. 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. I read some artcles on MSDN but still I am clear how to access the code from 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}" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.