编译绑定
开启或禁用编译绑定
<!--设置DataType并开启全局绑定 -->
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:MyViewModel"
x:CompileBindings="True">
<StackPanel>
<TextBlock Text="Last name:" />
<TextBox Text="{Binding LastName}" />
<TextBlock Text="Given name:" />
<TextBox Text="{Binding GivenName}" />
<TextBlock Text="E-Mail:" />
<!-- 在绑定标记中设置DataType -->
<TextBox Text="{Binding MailAddress, DataType={x:Type vm:MyViewModel}}" />
<!-- 我们无法在编译绑定中绑定到方法,所以对于按钮需要做出让步 -->
<Button x:CompileBindings="False"
Content="Send an E-Mail"
Command="{Binding SendEmailCommand}" />
</StackPanel>
</UserControl>CompiledBinding标记
ReflectionBinding标记
已知限制
最后更新于