This is a migrated thread and some comments may be shown as answers.

Binding not fired

4 Answers 651 Views
SlideView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Veteran
Simon asked on 20 May 2020, 09:22 AM

I have a number of items in my template I am trying to bind custom objects to. That part works fine for the same control in other forms etc but the property change code it never fired

 

 

 public static readonly BindableProperty RowItemProperty = BindableProperty.Create(
             nameof(RowItem),
             typeof(CSFormSwitchLine),
             typeof(CSSwitch),
             defaultValue: null,
             defaultBindingMode: BindingMode.TwoWay,
            propertyChanged: RowItemUpdated
        );

        public CSFormSwitchLine RowItem { get; set; }

        private static void RowItemUpdated(BindableObject bindable, object oldValue, object newValue)
        {

 

 

4 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 20 May 2020, 05:01 PM

Hi Simon,

Thank you for sharing the snippet, however it's impossible to tell you what's wrong from only that code (I'd need the rest of the UI and view model to recreate the issue).

What I can say is that you should review the BindableProperty's setup, the RowItem accessor looks incorrect (it doesn't even use the BindableProperty). Please follow the directions in the Microsoft documentation here https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/bindable-properties (pay attention to the accessor's setter and getter).

If you have any further trouble, help for BindableProperties is better sought after on StackOverflow or XamarinChat (live chat on Slack, invite yourself here). The Telerik forums are specific to problems with the UI for Xamarin controls themselves.

Regards,
Lance | Team Lead - US DevTools Support
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Simon
Top achievements
Rank 1
Veteran
answered on 21 May 2020, 08:14 AM

Hi Lance

I missed the xaml first time. how much / what do you need? its part of a larger project so I am trying to not provide way to much information to be confusing. as for the Bindable property, that is completely working in a Radlist and for a few other controls I have done its just SlideView that it doesn't seem to work on

 

                <local:DashboardItemTemplateSelector.DashboardTemplate>
                    <DataTemplate>
                        <telerikCommon:RadDockLayout>

                            <StackLayout Orientation="Vertical" telerikCommon:RadDockLayout.Dock="Top"  HorizontalOptions="Center">
                                <Label Text="{Binding StepTitle}" HorizontalTextAlignment="Center" TextColor="{StaticResource DarkGreyColor}"/>
                                <Label Text="{Binding SubTitle1}" HorizontalTextAlignment="Center" />
                                <Label Text="{Binding SubTitle2}" HorizontalTextAlignment="Center" />
                                <Label Text="{Binding StepDestination}" FontSize="28" HorizontalTextAlignment="Center" />
                            </StackLayout>
                            
                            <StackLayout Orientation="Vertical" telerikCommon:RadDockLayout.Dock="Bottom" Margin="30" HorizontalOptions="Center">
                                <controls:DSRadButton x:Name="button" Text="{x:Static resources:AppResources.Skip}" 
                                                      Style="{StaticResource buttonStyleWhite}" 
                                                      HorizontalOptions="End" WidthRequest="100" 
                                                      TextColor="{StaticResource IndigoLightColor}"
                                                      BackgroundColor="Transparent" Pressed="Skip_Pressed"/>
                                <controls:DSRadButton x:Name="mainButton" Text="Button" 
                                                      Style="{StaticResource buttonStyle}" HorizontalContentAlignment="Center" 
                                                      Pressed="MainButton_Pressed"
                                                      BackgroundColor="{StaticResource IndigoLightColor}"   DSObject="{ Binding  ., Converter={StaticResource ObjectConverter}}" />
                                <Label Text="{Binding StepNextSub1}" HorizontalTextAlignment="Center" Margin="0" Padding="0" />
                                <Label Text="{Binding StepNextSub2}" HorizontalTextAlignment="Center" Margin="0" Padding="0" />
                                <controls:DSSwitch Grid.Column="0" Grid.Row="1" RowItem="{ Binding  .}"   />
                            </StackLayout>

                            <Label Text="{Binding StepInstructions}" HorizontalOptions="Center" Margin="20" />
                        </telerikCommon:RadDockLayout>
                    </DataTemplate>
                </local:DashboardItemTemplateSelector.DashboardTemplate>
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 21 May 2020, 04:59 PM

Hello Simon,

Thank you for the ItemTemplate. The previous code you shared is for a CSSwitch control. In that SlideView template, there is no CSSwitch control anywhere that I can see (only a DSSwitch). If that isn't a typo, then that would explain why a breakpoint isn't being hit inside the CSSwitch control's property.

Finally, in Xamarin, you do not need to use a dot accessor for the binding, just use:

< ... RowItem="{Binding}"   />

Demo Test

I checked your setup and everything is working as expected. I attached my test app for you to compare.

When you run it, notice the checkbox and the text ro the right of the checkbox. Those values are directly set from the following binding:

<local:CSSwitch RowItem="{Binding}" />

The RowItem BindableProperty is configured per Microsoft's guidance for Xamarin.Forms:

public static readonly BindableProperty RowItemProperty = BindableProperty.Create(
    "RowItem", typeof(CSSwitchLine), typeof(CSSwitch), null, propertyChanged: OnRowItemChanged);

// This is accessor that a BindableProperty uses
public CSSwitchLine RowItem
{
    get => (CSSwitchLine)GetValue(RowItemProperty);
    set => SetValue(RowItemProperty, value);
}

private static void OnRowItemChanged(BindableObject bindable, object oldValue, object newValue)
{
    if (bindable is CSSwitch self && newValue is CSSwitchLine sl)
    {
        self.settingTitleLabel.Text = sl.SettingTitle;
        self.settingCheckBox.IsChecked = sl.SettingEnabled;
    }
}

Here's the result at runtime:

Here's the DataTemplate (the DockLayout parent is unrelated)

<DataTemplate x:DataType="local:CSSwitchLine">
    <Grid>
        <StackLayout Spacing="10"
                     VerticalOptions="Center"
                     HorizontalOptions="Center">
            <Label Text="{Binding SwitchLineTitle}" />

            <!-- This passes down the CSSwitchLine instance to the switch -->
            <local:CSSwitch RowItem="{Binding}" />
        </StackLayout>
    </Grid>
</DataTemplate>

With that demo to compare against, you should be able to isolate the problem with the current code you're using.

Further Xamarin Development Debugging

Debugging general Xamarin programming problems that are unrelated to the UI for Xamarin controls falls outside the scope of Telerik support. However, I'm willing to make an exception to the policy if you can take the following steps:

  1. Update my attached demo with your code so that it replicates the problem
  2. Open a new support ticket and attach the reproducible application

Once the support team sees the ticket come in, it will be assigned to me and I will investigate it after hours.

Regards,
Lance | Team Lead - US DevTools Support
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Simon
Top achievements
Rank 1
Veteran
answered on 29 May 2020, 02:38 PM
Thank you very much putting your binding methods into mine now works.
Tags
SlideView
Asked by
Simon
Top achievements
Rank 1
Veteran
Answers by
Lance | Manager Technical Support
Telerik team
Simon
Top achievements
Rank 1
Veteran
Share this question
or