【发布时间】:2020-10-04 14:01:27
【问题描述】:
我已经这样定义了我的风格:
<ContentView.Resources>
<ResourceDictionary>
<Style TargetType="Entry" x:Key="IntegralEntryBehavior">
<Setter Property="Behaviors" Value="valid:EntryIntegerValidationBehavior"/>
</Style>
</ResourceDictionary>
</ContentView.Resources>
还有多个类似的Entries:
<StackLayout Grid.Column="0" Grid.Row="0">
<Entry Style="{StaticResource IntegralEntryBehavior}"/>
</StackLayout>
如果我像这样定义 Entry 行为,我会收到一个错误,即 Entry.Behaviors property is readonly,但可以在不使用 Entry 中的 Style 属性的情况下定义行为:
<Entry.Behaviors>
<valid:EntryIntegerValidationBehavior/>
</Entry.Behaviors>
这些方法有什么区别?为什么只有第二种方法有效?是否可以修改第一种方法以使其工作?我正在寻找一种比第二个选项更短的方法来为每个条目定义此行为。
【问题讨论】:
标签: xaml xamarin xamarin.forms