嘿伙计们,我是Xamarin的新手,所以请记住这一点!:)
我遇到了使用x:Reference滑块的问题,我知道stackoverflow上有类似的问题,但它们比这个更复杂
这是完整的xaml代码
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="exampleApp.QuotesPage">
<ContentPage.Content>
<StackLayout>
<Button x:Name="next" Text="next" Clicked= "Handle_Clicked">
</Button>
<Label Text="{Binding Source={x:Reference slider}, Path=Value,
StringFormat='Value is {0:F2}'}" />
<Slider Maximum="50" Minimum="12"/>
<Label Text="QUOTE" x:Name ="quoteLabel"></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
这是发生错误的地方:
<Label Text="{Binding Source={x:Reference slider}, Path=Value,
StringFormat='Value is {0:F2}'}" />
Run Code Online (Sandbox Code Playgroud)
请帮忙!!谢谢
Slider您绑定到标签的文本属性的那个没有x:Name附加到它,因此Label抛出无法找到名称的错误slider:
<StackLayout>
<Button x:Name="next" Text="next" Clicked= "Handle_Clicked" />
<Label Text="{Binding Source={x:Reference slider}, Path=Value, StringFormat='Value is {0:F2}'}" />
<Slider x:Name="slider" Maximum="50" Minimum="12" />
<Label Text="QUOTE" x:Name="quoteLabel" />
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
仅供参考:通过将Xaml编译器应用于单个页面,您可以在编译时捕获这些类型的错误:
[XamlCompilation (XamlCompilationOptions.Compile)]
Run Code Online (Sandbox Code Playgroud)
或者在汇编级别编译所有XAML页面:
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
Run Code Online (Sandbox Code Playgroud)
回复:https://developer.xamarin.com/guides/xamarin-forms/xaml/xamlc/
| 归档时间: |
|
| 查看次数: |
496 次 |
| 最近记录: |