Bug 37289 - Initial value of button text in binding is not used
Summary: Initial value of button text in binding is not used
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.0.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-12-26 06:14 UTC by Mike
Modified: 2016-01-15 08:12 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Mike 2015-12-26 06:14:25 UTC
I have the following xaml that uses a custom viewcell.  It uses a collection of a little class I have called WordViewModel.  This class exposes a property for "ButtonText" like this within the codebehind file:

        public string ButtonText { get; set; }

Within the constructor of the WordViewModel, I initialize ButtonText to "hi".  This value is not used.

I have an event handler on the button that calls a function called "ToggleRecordingCommand" - all that command does is set ButtonText to something.  This value does correctly update the button text.

The bug is that the initial value is not being read at creation time of the viewcell.

Here's the xaml I was using.

    <ListView x:Name="mListView" ItemsSource="{Binding AllWords}" SelectedItem="{Binding CurrentWord, Mode=TwoWay}" SeparatorVisibility="Default" SeparatorColor="Aqua">
          <ViewCell x:Name="viewCell">
                  <RowDefinition Height="*" /> <!-- a single row -->
                  <ColumnDefinition Width="*" />  <!-- hidden select box -->
                  <ColumnDefinition Width="4*" />  <!-- the word -->
                  <ColumnDefinition Width="2*" />  <!-- record / pause -->

                <Label Grid.Row="0" Grid.Column="1" Text="{Binding Text}" Style="{x:DynamicResource DefaultLabelStyle}"/>
                <Button Grid.Row="0" Grid.Column="2"
                        Command="{Binding ToggleRecordingCommand}"
                        Text="{Binding ButtonText}"
                        BackgroundColor="Color.Transparent" />            
Comment 1 Mike 2015-12-26 06:18:53 UTC
Also, please try an Image="{Binding ButtonImage}".  This crashes the app if instead of updating the ButtonText I just try to update the image.  I may file a separate bug for this, but I think it might be close enough not to.
Comment 2 Stephane Delcroix 2016-01-14 13:01:05 UTC
Hi Mike,

I tried to reproduce understand and reproduce your issue, but I had no problem at all displaying the default value for the button.

Could you please share the smallest possible project reproducing this issue so we can look at it ?

Thanks a lot,

The Xamarin Forms team.
Comment 3 Mike 2016-01-15 03:37:15 UTC
Hi Stephane,

Once again I've created a small project to reproduce the issue I'm seeing and there's no problem. I must have done something wrong in my code.  I will keep the demo project handy in case I can see the difference if it ever turns up again.

Thanks a lot for looking into this.

Comment 4 Stephane Delcroix 2016-01-15 08:12:52 UTC
Closing as per comment #3