Bind a subclass to property

Posted by Neir0 on Stack Overflow See other posts from Stack Overflow or by Neir0
Published on 2010-03-31T00:29:20Z Indexed on 2010/03/31 0:33 UTC
Read the original article Hit count: 489

Filed under:
|
|
|

Hi i have a simple question. Ofcourse it has many answers but i cannt choose right keywords to google. How i can bind a subclass to my wpf control?

for example: It's my class.

public class SiteFieldInfo<T>
    {
        public string Name { get; set; }
        public T Value { get; set; }
        public List<string> PositiveXPathExpressions { get; set; }
        public List<string> NegativeXPathExpressions { get; set; }
    }

    public class SiteInfo
    {
        public SiteFieldInfo<string> Author { get; set; }
        public SiteFieldInfo<DateTime> Date { get; set; }
        public SiteFieldInfo<string> Source { get; set; } 
    }

And i want to bind property Value from SiteFieldInfo to Text property of TextBox control.

c# code:

stackPanel1.DataContext = SiteInfoInstance;

xaml code:

<StackPanel Name="stackPanel1">
<TextBlock Text="Author" Grid.Row="0" Grid.Column="0" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=Author.Value}" />
</StackPanel>

It's not working. What is right syntax or any alternatives?

© Stack Overflow or respective owner

Related posts about data

Related posts about binding