Neir0
Neir0

Reputation: 13367

Bind a subclass to property

I have a simple question. Of course it has many answers but I cannot 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, It's work well. I am just stupid. How to close question?

Upvotes: 2

Views: 2218

Answers (2)

Michael Detras
Michael Detras

Reputation: 211

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.

Upvotes: 0

devuxer
devuxer

Reputation: 42354

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.

Upvotes: 1

Related Questions