C# 如何使用MVVM在组合框WPF中获取值

C# 如何使用MVVM在组合框WPF中获取值,c#,wpf,mvvm,C#,Wpf,Mvvm,下一段代码有点奇怪,但我必须修改以获得选择的值,在XAML中;从视图模型中的属性获取ItemsSource。。。 XAML 在MVVM代码中: public List<String> ReglaMateABC { get { List<String> data = new List<string>(); data.Add(ControlesResource.Te

下一段代码有点奇怪,但我必须修改以获得选择的值,在XAML中;从视图模型中的属性获取ItemsSource。。。 XAML


在MVVM代码中:

    public List<String> ReglaMateABC
    {
        get
        {
            List<String> data = new List<string>();
            data.Add(ControlesResource.TextoReglaMatematicaAB);
            data.Add(ControlesResource.TextoReglaMatematicaC);   
            data.Add(ControlesResource.TextoReglaMatematicaD);             
            return data;
        }
    // this set is added for me
        set
        {
              **SomeVariable** = value;
              this.RaisePropertyChanged(() => this.ListTipoPpa);
        }

    }
public List reglamatabc
{
收到
{
列表数据=新列表();
添加(ControlesResource.TextoReglaMatematicaAB);
data.Add(ControlesResource.textoregramatematicac);
添加(ControlesResource.textoRegamateMatiCAD);
返回数据;
}
//这套是为我加的
设置
{
**SomeVariable**=值;
this.RaisePropertyChanged(()=>this.ListTipoPpa);
}
}
控件resource.TextoReglaMatematicaxx取自资源文件

我应该使用什么类型的变量(SomeVariable

正在使用Prism.ViewModel,并且RaiseProperty更改了工作所需的内容

更新这是在XAML文件中绑定的传输对象类,位于 SelectedItem=“{Binding Path=Contribucion.ReglaMatematicaTexto

    public class ContribucionTO
{
    /// <summary>
    /// Identificador de la Contribución.
    /// </summary>
    public string ContribucionId { get; set; }

    /// <summary>
    /// Vigencia de la contribución.
    /// </summary>
    public VigenciaTO Vigencia { get; set; }

    /// <summary>
    /// Nombre de la contribución.
    /// </summary>
    [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "ContribucionTONombreRequerido", ErrorMessageResourceType = typeof(MensajesValidacionResource))]
    [StringLength(150, MinimumLength = 0, ErrorMessageResourceName = "ContribucionTONombreLongitud", ErrorMessageResourceType = typeof(MensajesValidacionResource))]
    public string Nombre { get; set; }

    /// <summary>
    /// Descripción de la contribución.
    /// </summary>
    [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "ContribucionTODescripcionRequerido", ErrorMessageResourceType = typeof(MensajesValidacionResource))]
    [StringLength(150, MinimumLength = 0, ErrorMessageResourceName = "ContribucionTODescripcionLongituda", ErrorMessageResourceType = typeof(MensajesValidacionResource))]
    public string Descripcion { get; set; }

    /// <summary>
    /// Valor de la tarifa de la contribución.
    /// </summary>        
    public decimal Tarifa { get; set; }

    /// <summary>
    /// Indica si la tarifa de la contribución se actualiza o no.
    /// </summary>
    public bool ActualizaTarifa { get; set; }

    /// <summary>
    /// Indica si la regla matemática a utilizar es A+B (True) o C (False)
    /// </summary>
    public bool ReglaMatematica { get; set; }

    /// <summary>
    /// Indicador base de la contribución.
    /// </summary>
    public IndicadorTO IndicadorBase { get; set; }

    /// <summary>
    /// Convocatorias que se excluyen de la distribución de la contribución.
    /// </summary>
    public List<ConvocatoriaTO> ConvocatoriasExcluidas { get; set; }

}//end ContribucionTO
公共类贡献
{
/// 
///共同财产鉴定人。
/// 
公共字符串ContribucionId{get;set;}
/// 
///共同投资银行。
/// 
公共Vigencia Vigencia{get;set;}
/// 
///名义上的共同责任。
/// 
[必需(AllowEmptyStrings=false,ErrorMessageResourceName=“ContribionTonomBrerequeriedo”,ErrorMessageResourceType=typeof(MensajesValidacionResource))]
[StringLength(150,MinimumLength=0,ErrorMessageResourceName=“ContribionTonomBreLongitud”,ErrorMessageResourceType=typeof(MensAjesValidActionResource))]
公共字符串Nombre{get;set;}
/// 
///描述合同条款。
/// 
[必需(AllowEmptyStrings=false,ErrorMessageResourceName=“ContribuionToDescriptionReconRequirido”,ErrorMessageResourceType=typeof(MensAjesValidActionResource))]
[StringLength(150,MinimumLength=0,ErrorMessageResourceName=“ContribuionToDescriptionOnLogituda”,ErrorMessageResourceType=typeof(MensAjesValidActionResource))]
公共字符串描述符{get;set;}
/// 
///塔里法·德拉图布西翁之谷(Valor de la tarifa de la contribución)。
///         
公共十进制Tarifa{get;set;}
/// 
///这是第三个项目的具体实施情况。
/// 
公共bool-zatarifa{get;set;}
/// 
///材料使用率指标a+B(真)o C(假)
/// 
公共布尔正则表达式{get;set;}
/// 
///印度共和国基地。
/// 
公共指示符到指示符基{get;set;}
/// 
///共同财产分配委员会。
/// 
公共列表集合器Excluidas{get;set;}
}//结束分担

对于变量类型,您应该使用列表。但是我发现,在计算并在get访问器上返回列表时设置它是没有意义的

对于所选的值,在xaml代码中有SelectedItem绑定,并且应该使用Contribucion.ReglaMaticaTexto属性

编辑: 从评论中的讨论中,我了解到您应该使用另一个属性更新ViewModel类以绑定ComboBox的选择。您不应该直接绑定到Contribion类

一项建议是:

private string selectedMathRule; 
public string SelectedMathRule 
{ 
  get { return this.selectedMathRule; } 
  set { SetProperty(ref this.selectedMathRule, value); } 
}

不获取Contribion.ReglamaticTextOI的值我不明白你在尝试做什么。你怎么设置了绑定?我试图获取所选项目的值,通过设置它的方式,它绑定到Contribion.ReglamaticTextO。这个属性定义在哪里?它的setter上是否有RaiseProperty更改?还有,为什么您是否正在为ListIpoppa引发更改事件?
private string selectedMathRule; 
public string SelectedMathRule 
{ 
  get { return this.selectedMathRule; } 
  set { SetProperty(ref this.selectedMathRule, value); } 
}