cimbalino / Cimbalino-Phone-Toolkit

Cimbalino Windows Phone Toolkit
MIT License
78 stars 32 forks source link

System.NullReferenceException #46

Closed tobitech closed 9 years ago

tobitech commented 9 years ago

I tried to bind the IsVisible property of an applicationbariconbutton to a property in a ViewModel but didn't work, so I then tried to control the visibility and it's IsEnabled property in the code behind but it throws a System.NullReferenceException and tells me to check to see if it null

pedrolamas commented 9 years ago

Hi @tobitech, can you please paste the XAML you're trying to use? In what method are you trying to change those properties manually?

tobitech commented 9 years ago

This is my xaml

<i:Interaction.Behaviors>
        <cimbalinoBehaviors:ApplicationBarBehavior>
            <!--<cimbalinoBehaviors:ApplicationBarIconButton x:Name="home"
                                                             IconUri="/Assets1/AppBar/basecircle.png"
                                                             Text="home"
                                                             IsEnabled="True"
                                                         Click="home_Click"/>-->
            <cimbalinoBehaviors:ApplicationBarIconButton x:Name="pcappbar"
                                                             IconUri="/Assets1/AppBar/send.text.png"
                                                             Text="comment"
                                                             IsEnabled="True"
                                                             Click="pcappbar_Click"/>
            <cimbalinoBehaviors:ApplicationBarIconButton x:Name="shareappbar"
                                                             IconUri="/Assets1/AppBar/share.png"
                                                             Text="share"
                                                             IsEnabled="True"
                                                             Command="{Binding ShareButtonCommand,Mode=TwoWay}"/>
            <cimbalinoBehaviors:ApplicationBarIconButton x:Name="dvappbar"
                                                         IconUri="/Assets1/AppBar/download.png"
                                                         Text="download"
                                                         IsEnabled="True"
                                                         IsVisible="True"
                                                         Click="downloadappbar_Click"/>
            <cimbalinoBehaviors:ApplicationBarBehavior.MenuItems>
                <cimbalinoBehaviors:ApplicationBarMenuItem x:Name="vcmenu"
                                                               Text="view comments"
                                                           IsEnabled="True"
                                                               Click="vcmenu_Click"/>
                <cimbalinoBehaviors:ApplicationBarMenuItem x:Name="rvmenu"
                                                               Text="report this video"
                                                           IsEnabled="True"
                                                               Click="rvmenu_Click"/>
                <!--<cimbalinoBehaviors:ApplicationBarMenuItem x:Name="dvmenu"
                                                               Text="download"
                                                           IsVisible="True"
                                                           IsEnabled="True"
                                                           Click="downloadappbar_Click"/>-->
            </cimbalinoBehaviors:ApplicationBarBehavior.MenuItems>
        </cimbalinoBehaviors:ApplicationBarBehavior>
    </i:Interaction.Behaviors>

and it's like, IsEnabled wasn't set in your sample project code

pedrolamas commented 9 years ago

IsEnabled = True and IsVisible = True are the default values, should be no need to put those in!

pedrolamas commented 9 years ago

Can you post the complete stack trace of the exception also?

tobitech commented 9 years ago

StackTrace at VideoDetailPage.d__0.MoveNext() I actually did this

dvappbar.IsEnabled = false; 

on the OnNavigatedTo event of the page

pedrolamas commented 9 years ago

Ok, that's it then: dvappbar is null, as you can't use x:Name on behavior elements!

tobitech commented 9 years ago

So what should I do to control the Visibility or it's enability?

pedrolamas commented 9 years ago

Ideally you should do that from the ViewModel, just binding to those properties!

tobitech commented 9 years ago

I will do that, thanks for attending to me. I'm sorry I created the first issue on this repo

pedrolamas commented 9 years ago

No problem! :) closing this for now!