0

在我的 WPF 应用程序中,一个文档有两个属性,报告名称和文件名称。在 UI 中,用户填写报告名称,文件名将自动填充报告名称作为默认值。在创建新文档的对话框中,我有

<TextBox x:Name="tbReportName" Grid.Row="0" Grid.Column="1" Style="{StaticResource DialogInputStyle}"
         Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=ReportName,
                ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />

 <TextBox  Grid.Row="5" Grid.Column="1" Text="{Binding Text,ElementName=tbReportName,UpdateSourceTrigger=PropertyChanged,Mode=OneWay,Converter={StaticResource safefilenamConverter}}"  Style="{StaticResource DialogInputStyle}" >

报告名称绑定到视图模型中的属性,我需要对文件名执行相同操作

用户可以选择使用默认文件名或在文本框中更改它。我需要将文件名文本框的值绑定到我的视图模型中的属性,但该绑定已用于从报告名称文本框中获取值。

如果我想保留 MVVM,不知道该使用什么

Multibinging,触发器....有什么想法吗?

4

1 回答 1

0

它必须在 XAML 中吗?如果在设置 ReportName 时它为空,则可以只设置 FileName 属性:

private string _reportName;
public string ReportName
{
    get { return _reportName; }
    set
    {
        _reportName = value;
        if(string.IsNullOrEmpty(FileName))
        {
            FileName = _reportName;
        }
        OnPropertyChanged("ReportName");
    }
}

private string _fileName;
public string FileName
{
    get { return _fileName; }
    set
    {
        _fileName = value;
        OnPropertyChanged("FileName");
    }
}
于 2012-10-26T21:07:17.127 回答