我用一些值声明了枚举,我想传递给我的格式化参数。这是我的 C# 代码:
public MyControllerView()
{
ContentEntry.TextChanged += Entry_TextChanged;
}
public string Formated
{
get
{
return formatedText;
}
set
{
formatedText = value;
}
}
public enum FomationType
{
NameValidation,
CardNrValidation,
ExpDate
};
// here I want to use my enum in switch statement, but I can't, because I can't modify my method parameters
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
{
FomationType FomationType;
switch (FomationType)
{
case FomationType.NameValidation:
ToUpper(ent);
break;
case FomationType.CardNrValidation:
CardNumberValidation(ent);
break;
case FomationType.ExpDate:
ExpDate(ent, e);
break;
}
}
这是我的带有格式化参数的 XAML 代码,我必须在其中传递我的枚举值:
<ContentPage.Content>
<StackLayout Padding="7,7,7,7" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Spacing="0">
<cv:MyControllerView LabelText="some text 4" Placeholder="some text 4" Formated="" Keyboard="Text" >
</cv:MyControllerView>
<cv:MyControllerView LabelText="some text 3" Placeholder="some text 3" Formated="" Keyboard="Numeric" >
</cv:MyControllerView>
<cv:MyControllerView LabelText="some text 2" Placeholder="some text 2" Formated="" Keyboard="Numeric" >
</cv:MyControllerView>
</StackLayout>
</ContentPage.Content>
现在我应该如何将 FormationType anum 传递给 Formated=""参数。我应该将我的格式化字符串分配给枚举值吗?
最佳答案
好吧,解决这个关于this的问题论坛帖子帮助我弄清楚了一切。这是我的 C# 代码:
public enum FomationType
{
NameValidation,
CardNrValidation,
ExpDate
};
public FomationType Formated { get; set; }
这里是我的 switch 声明:
var ent = sender as Entry;
switch (Formated)
{
case FomationType.NameValidation:
ToUpper(ent);
break;
case FomationType.CardNrValidation:
CardNumberValidation(ent);
break;
case FomationType.ExpDate:
ExpDate(ent, e);
break;
}
XAML 属性不变:
<cv:MyControllerView LabelText="some text 4" Placeholder="some text 4" Formated="NameValidation" Keyboard="Text" >
关于c# - xamarin forms 如何将枚举值传递给 XAML 并在 switch 语句中使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39996280/