I am trying to use a multi-binding inside of a BindableLayout and I can't get the "Answer" binding to scope correctly.
This line: <Binding Path="SelectedAnswers" Source="{x:Reference this}" />
is working correctly and is passed into the converter.
This line: <Binding Path="Answer" Source="{RelativeSource Mode=Self}" />
is just null;
You can see on the Button text property I am using "Answer" there too and it is not null.
<FlexLayout Wrap="Wrap" BindableLayout.ItemsSource="{Binding CurrentQuestion.SurveyQuestionAnswers}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="viewmodels:SurveyQuestionAnswerViewModelRead">
<StackLayout>
<Button Text="{Binding Answer}" Command="{Binding QuestionAnsweredCommand, Source={x:Reference this}}" CommandParameter="{Binding .}" >
<Button.IsVisible>
<MultiBinding Converter="{StaticResource ListAnyMultiValueConverter}">
<Binding Path="SelectedAnswers" Source="{x:Reference this}" />
<Binding Path="Answer" Source="{RelativeSource Mode=Self}" />
</MultiBinding>
</Button.IsVisible>
</Button>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
1条答案
按热度按时间zc0qhyus1#
这个问题是对
{RelativeSource Mode=Self}
的误解。那就是在Button元素上寻找一个属性Answer
。当然没有这样的属性。(You可以使用此模式来引用按钮的
Text
属性。但也可以直接绑定到Text所绑定的同一个变量。)应执行的操作:
<Binding Path="Answer"/>
这将在
BindingContext
中显示,就像{Binding Answer}
在Button Text上显示一样。