【发布时间】:2016-06-24 05:36:38
【问题描述】:
目标:
我想从 ExtendableButtonList(自定义视图)中的 ContentPage(管理 XAML 的类)运行一些方法。
问题:
ActionHandler - 表示要在 ExtendableButtonList 中调用的事件 - 始终等于 null。其他所有属性都以相同的方式配置,而不是这样。
甚至可以使用绑定来传递方法吗?
我确定我没有将空值传递给我的对象。
XAML:
<ListView x:Name="emView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="20">
<StackLayout BackgroundColor="Silver" Padding="20">
[...]
<customControls:ExtendableButtonList ActionHandler="{Binding ActionHandler}"></customControls:ExtendableButtonList>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
可扩展按钮列表:
public class ExtendableButtonList : StackLayout
{
public static readonly BindableProperty ActionHandlerProperty = BindableProperty.Create(
propertyName: "ActionHandler",
returnType: typeof(OneOfButtonClickedHandler),
declaringType: typeof(ExtendableButtonList),
defaultValue: default(OneOfButtonClickedHandler));
public OneOfButtonClickedHandler ActionHandler
{
get { return (OneOfButtonClickedHandler)GetValue(ActionHandlerProperty); }
set { SetValue(ActionHandlerProperty, value); }
}
public delegate void OneOfButtonClickedHandler(int buttonId, int action);
public event OneOfButtonClickedHandler OneOfButtonsClicked;
public ExtendableButtonList()
{
[...]
PropertyChanged += CheckIfPropertyLoaded;
}
void CheckIfPropertyLoaded(object sender, PropertyChangedEventArgs e)
{
//wait until property ActionHandler will be loaded
if(e.PropertyName == "ActionHandler")
{
OneOfButtonsClicked += ActionHandler;
}
}
[...]
void CalculationsFinished(){
[...]
OneOfButtonsClicked(buttonId, action);
}
}
【问题讨论】:
标签: c# xaml xamarin xamarin.forms