Xaml View可查看ContentPage和ContentView之间的数据绑定
View可查看ContentPage和ContentView之间的数据绑定 我使用的是Xamarin表单手册中的PlaneRotationDemoPage示例 我有一个ContentPage,希望将滑块控件从ContentPage移动到另一个XAML/CS文件中的ContentView中。内容视图本身似乎被正确引用,但是滑块控件绑定似乎没有正确连接。我收到一个错误“无法解析元素上的名称”Xaml View可查看ContentPage和ContentView之间的数据绑定,xaml,xamarin,view,binding,Xaml,Xamarin,View,Binding,View可查看ContentPage和ContentView之间的数据绑定 我使用的是Xamarin表单手册中的PlaneRotationDemoPage示例 我有一个ContentPage,希望将滑块控件从ContentPage移动到另一个XAML/CS文件中的ContentView中。内容视图本身似乎被正确引用,但是滑块控件绑定似乎没有正确连接。我收到一个错误“无法解析元素上的名称” ... ... //新内容视图 //仅将下面的滑块移动到ContentView中 //ContentPag
...
...
//新内容视图
//仅将下面的滑块移动到ContentView中
//ContentPage上下面的标签应与移动到ContentView的滑块绑定
在ContentView文件中
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PlaneRotationDemo.SliderTest">
<ContentView.Content>
//slider moved here
<Slider x:Name="rotationSlider"
Maximum="360"
Value="{Binding Source={x:Reference Name=handA}, //should bind with handA in the ContentPage
Path=Rotation}"
/>
</ContentView.Content>
//滑块移到了这里
ContentPage中的标签需要引用ContentView中的滑块
现在在ContentView中的滑块需要引用ContentPage中的handA RoundedBoxView
这在XAML中可能吗 当您创建Xaml时,它会创建一个cs和一个自动生成的cs(Xaml.g.cs)文件,您的x:Name引用了其中定义的文件。由于您的SliderTest.xaml文件未定义handA,因此出现此错误。在用户控件(内容视图)中公开一个BindableProperty。将BindableProperty绑定到滑块控件中的Value属性 XAML看起来像这样
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PlaneRotationDemo.SliderTest" x:Name=UC>
<ContentView.Content>
//slider moved here
<Slider x:Name="rotationSlider"
Maximum="360"
Value="{Binding MyBindableProperty, Source={x:Reference Name=UC},
Path=Rotation}"/>
</ContentView.Content>
<local:RoundedBoxView x:Name="handA"
StrokeThickness="2"
CornerRadius = "40"
Stroke = "White"
Color = "Gray"
AbsoluteLayout.LayoutBounds = "152.0,248.0,15.0,15.0"
/>
<local:SliderTest MyBindableProperty={Binding Source={x:Reference handA}}/>
//滑块移到了这里
用法是这样的
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PlaneRotationDemo.SliderTest" x:Name=UC>
<ContentView.Content>
//slider moved here
<Slider x:Name="rotationSlider"
Maximum="360"
Value="{Binding MyBindableProperty, Source={x:Reference Name=UC},
Path=Rotation}"/>
</ContentView.Content>
<local:RoundedBoxView x:Name="handA"
StrokeThickness="2"
CornerRadius = "40"
Stroke = "White"
Color = "Gray"
AbsoluteLayout.LayoutBounds = "152.0,248.0,15.0,15.0"
/>
<local:SliderTest MyBindableProperty={Binding Source={x:Reference handA}}/>
希望这能有所帮助。我尝试将xmlns:local=“clr namespace:PlaneRotationDemo;assembly=PlaneRotationDemo”添加到SliderTest.Xaml的标题中,但如何添加到绑定中?Value=“{Binding Source={x:Reference Name=local:handA}不能与local:handA的添加一起工作