XamarinCommunityToolkit icon indicating copy to clipboard operation
XamarinCommunityToolkit copied to clipboard

null reference exception when setting up BindingContext = new TheViewModel(); when badge view is used on the same page (ContentPage)

Open samir-dahal opened this issue 3 years ago • 2 comments

Description

Ok this is weird but when you use a badge view in your page (Content Page) and try to set the binding context for that page You get "Object reference not set to an instance of an object" exception But when I comment the badgeview control it does not throw the exception. `

public partial class HomePage : BaseContentPage
{
    public HomePage()
    {
       //create a badeview in code xaml
        InitializeComponent();
        BindingContext = new HomePageViewModel(); << here is the null reference exception
    }
}

HomePage.xaml
<xct:BadgeView
        Grid.Column="1"
        BackgroundColor="{StaticResource PrimaryPink}"
        Text="MARKET CLOSED"
        TextColor="White" />

`

Steps to Reproduce

  1. Create a xaml file and add BadgeView control from XCT (Xamarin Community Toolkit)
  2. Create a view model for that page and set the binding context either from code behind or xaml
  3. Try to run the app

Expected Behavior

It should not throw an exception when setting up the badgeview in your xaml file and setting up the binding context for that page.

Actual Behavior

Throws null reference exeception when setting up bindingcontext for the page which contains badgeview

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:
    • iOS: Not tried on this platform
    • Android: Android 11 (Emulator) and Physical device (Android 9.0)
    • UWP: Not tried on this platform
  • Android Support Library Version:
  • Nuget Packages: https://www.nuget.org/packages/Xamarin.CommunityToolkit/
  • Affected Devices:

Workaround

Reproduction imagery

Reproduction Link

samir-dahal avatar Sep 21 '21 03:09 samir-dahal

This is happening to me also.

victordscott avatar May 25 '22 20:05 victordscott

Could you attach a small repro?

pictos avatar May 25 '22 21:05 pictos