【发布时间】:2018-05-29 05:41:45
【问题描述】:
我正在尝试在内容页面中加载内容视图。当我运行代码时,它不会点击我的内容视图。我正在从我的内容页面分配两个 Bindable 参数。
内容页面:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:templates="clr-namespace:G2.Scanner.Views.Templates"
xmlns:viewModelBase="clr-namespace:G2.Scanner.ViewModels.Base;assembly=G2.Scanner"
xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
xmlns:local ="clr-namespace:G2.Scanner.Views.Transaction"
x:Class="G2.Scanner.Views.Transaction.TransactionView"
viewModelBase:ViewModelLocator.AutoWireViewModel="true">
<local:GenerateScreen x:Name="generateScreen" ControllerName="{Binding ControllerName}" IsBusy="{Binding IsBusy}"/>
</ContentPage>
内容视图:
public partial class GenerateScreen : ContentView
{
#region BindableProperties
public static readonly BindableProperty ControllerNameProperty = BindableProperty.Create("ControllerName", typeof(string), typeof(GenerateScreen));
public static readonly BindableProperty IsBusyProperty = BindableProperty.Create("IsBusy", typeof(bool), typeof(GenerateScreen));
#endregion
#region Properties
public string ControllerName
{
get { return (string)GetValue(ControllerNameProperty); }
set { SetValue(ControllerNameProperty, value); }
}
public bool IsBusy
{
get { return (bool)GetValue(IsBusyProperty); }
set { SetValue(IsBusyProperty, value); }
}
#endregion
public GenerateScreen()
{
InitializeComponent();
DesignScreenAsync();
}
public async void DesignScreenAsync()
{
IsBusy = true;
// Some Design code..
#region render
scroll = new ScrollView
{
Content = layout
};
TransactionElements.Children.Add(scroll);
#endregion
IsBusy = false;
}
Content View 接受两个可绑定属性并在加载时使用。
内容视图 Xaml:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="G2.Scanner.Views.Transaction.GenerateScreen">
<ContentView.Content>
<StackLayout x:Name="TransactionElements"/>
</ContentView.Content>
</ContentView>
我希望在加载内容页面时呈现此视图。 我发现如果我不在内容视图中使用可绑定属性,这将有效。但根据我的要求,ContentView 类中的 ControllerName 和 IsBusy 应该是可绑定属性。 任何帮助为什么它没有点击这个视图。
【问题讨论】:
-
您是否调试过您的视图?调用
DesignScreenAsync时是否设置了绑定? -
@Johannes 它首先没有达到内容视图类。是的,我只是通过调试来尝试一切。
-
断点被放入构造函数和/或
DesignScreenAsync方法?没有人被击中? -
@DiegoRafaelSouza 在这两个地方都设置了断点,但没有命中。
标签: xamarin xamarin.forms