В целях стилизации и создания шаблонов я бы порекомендовал вам предоставить два свойства зависимостей, с которыми вы затем можете связать свои TextBox
es.
В вашем классе MainWindow
C # определите следующую только для чтениясвойства зависимостей:
#region FirstFile dependency property
public string FirstFile
{
get => (string)GetValue(FirstFileProperty);
private set => SetValue(FirstFilePropertyKey, value);
}
private static readonly DependencyPropertyKey FirstFilePropertyKey =
DependencyProperty.RegisterReadOnly(nameof(FirstFile),
typeof(string), typeof(MainWindow));
public static readonly DependencyProperty FirstFileProperty =
FirstFilePropertyKey.DependencyProperty;
#endregion
#region SecondFile dependency property
public string SecondFile
{
get => (string)GetValue(SecondFileProperty);
private set => SetValue(SecondFilePropertyKey, value);
}
private static readonly DependencyPropertyKey SecondFilePropertyKey =
DependencyProperty.RegisterReadOnly(nameof(SecondFile),
typeof(string), typeof(MainWindow));
public static readonly DependencyProperty SecondFileProperty =
SecondFilePropertyKey.DependencyProperty;
#endregion
Теперь привяжите свои текстовые поля к этим свойствам зависимостей, как показано ниже:
<TextBox Margin="0 0 0 5" Padding="2" x:Name="firstFilePath" Text="{Binding FirstFile}"/>
<TextBox Margin="0 0 0 5" Padding="2" x:Name="secondfilePath" Text="{Binding SecondFile}"/>
Свойства зависимостей обеспечивают необходимые механизмы уведомлений для WPF, которые облегчают нашу работу,Они предпочтительны для обязательных сценариев, когда это возможно.