tags:

views:

139

answers:

2

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" />
<TextBox Text="{Binding Path=Author.Value}" />
</StackPanel>

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


Sorry guys. It's work well. i am just stupid. How to close question?

+1  A: 

Are you absolutely positive that your SiteInfoInstance is populated with data? I don't see any problems with the way your classes are structured or with your XAML.

DanM
A: 

Is calling the ToString() method like here in XAML works? I thought the binding will automatically get the string representation of the source of the binding.

Michael Detras