Chris Kooken
Chris Kooken

Reputation: 33870

XAML Multibinding Path not working inside BindableLayout

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>

Upvotes: 0

Views: 435

Answers (1)

ToolmakerSteve
ToolmakerSteve

Reputation: 21243

The problem is a misunderstanding of {RelativeSource Mode=Self}. That is looking for a property Answer on the Button element. There is no such property of course.

(You could use this mode to refer to Text property of button. But might as well bind directly to the same variable that Text does.)

Do:
<Binding Path="Answer"/>

That will look in the BindingContext, just like {Binding Answer} did on Button Text.

Upvotes: 1

Related Questions