XAML多重系结路径无法在BindableLayout内部运作

s6fujrry  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(100)

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>
zc0qhyus

zc0qhyus1#

这个问题是对{RelativeSource Mode=Self}的误解。那就是在Button元素上寻找一个属性Answer。当然没有这样的属性。
(You可以使用此模式来引用按钮的Text属性。但也可以直接绑定到Text所绑定的同一个变量。)
应执行的操作:
<Binding Path="Answer"/>
这将在BindingContext中显示,就像{Binding Answer}在Button Text上显示一样。

相关问题