How to set property path for Data Binding in Data Template

290 Views Asked by At

I have the following DataTemplate in my App.xaml file:

<DataTemplate x:Key="OneSettingsEntryTemplate">
    <StackPanel Orientation="Horizontal">
        <TextBlock Style="{StaticResource StandardTextBlocksStyle}"
                   Text="{Binding Text}" />
        <TextBox Style="{StaticResource DefaultTextBoxesStyle}"
                 Text="{Binding Content}" />
    </StackPanel>
</DataTemplate>

and the following class which contains both Binding properties:

public class InputText
{
    private string Text { get; set; }
    private string Content { get; set; }

    public InputText(string text, string content)
    {
        Text = text;
        Content = content;
    }
}

The App.xaml file tells me Cannot resolve symbol text.
How can I tell the Data Template, which class respectively source it should use, so that Binding works?

1

There are 1 best solutions below

0
On

Alright, I found a solution that works for me. I knew I needed the DataType property but didn't know how to reference it, to another class. It looks like x:Type was what I missed:

<DataTemplate x:Key="OneSettingsEntryTemplate" DataType="{x:Type templateHelper:InputText}">

If there are better alternatives, please share it.