locked
problem in data binding in windows phone 8 RRS feed

  • Question

  • Hi,

    I have a longlistselector which has text block as its content. I binded this control with list.

    I have two binding, one with content of text block and other with color of text block.

    I am seeing correct result with content, but i am not seeing correct with color.

    Here is snippet of my xaml.

    <phone:LongListSelector x:Name="CategorySelection" Margin="5" ItemsSource="{Binding ListOfCategories}" Height="Auto" Width="Auto" HorizontalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto">
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <Grid>                                        
                    <TextBlock Text="{Binding CategoryName}" Style="{StaticResource PhoneTextTitle2Style}" Grid.Column="0" Grid.Row="0" Foreground="{Binding IsChecked, Converter={StaticResource boolToColorConverter}}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5">
                        <toolKit:ContextMenuService.ContextMenu>
                                            <toolKit:ContextMenu IsZoomEnabled="False">
                                                <toolKit:MenuItem Header="Pin To List" Click="MenuItem_Click" Visibility="{Binding IsChecked, Converter={StaticResource booleanToCollapseConverter}}"/>
                                                <toolKit:MenuItem Header="UnPin From List" Click="MenuItem_Click_1" Visibility="{Binding IsChecked, Converter={StaticResource booleanToVisibilityConverter}}"/>
                                            </toolKit:ContextMenu>
                                        </toolKit:ContextMenuService.ContextMenu>
                    </TextBlock>
                </Grid>
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>
    </phone:LongListSelector>

    Thanks in advance for help.

    Venkat

     

    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 3:25 AM

Answers

  • I did silly mistake in my view model.

    i am using open source BindableBase instead of Inotifypropertychanged implemenatation.

    I wrote my property like

    privatebool _isChecked;         publicbool IsChecked         {             get             {                 return _isChecked;             }             set             {

    _isChecked = value; //this causing the mistake. because this line of code, it is not sending the notification in SetProperty.                 SetProperty(ref _isChecked, value);             }         }

      thank you Jebarson for your time.


    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 11:57 AM

All replies

  • Are you talking about Foreground="{Binding IsChecked, Converter={StaticResource boolToColorConverter}}" If so then keeping a breakpoint on the converter is breaking there?

    All your questions about windows phone ends here http://howtowindowsphone.com

    Wednesday, August 14, 2013 3:32 AM
  • sadly control is not reaching to converter class?

    i am observing the same with contextmenu.

    if i add bind visibility property(with bool value ) of text block it is working fine..


    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 3:39 AM
  • Are you sure that IsChecked property is the right one, may be you can try binding it to a checkbox and verify?

    All your questions about windows phone ends here http://howtowindowsphone.com

    Wednesday, August 14, 2013 3:42 AM
  • with check box, it is working fine..

    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 3:45 AM
  • Is your converter public? Would you mind sharing a small sample

    All your questions about windows phone ends here http://howtowindowsphone.com

    Wednesday, August 14, 2013 3:53 AM
  • there is no problem with the convrter.

     

    publicsealedclassBoolToColorConverter : IValueConverter     {         publicobject Convert(object value, Type targetType, object parameter, CultureInfo language)         {             var temp = newSolidColorBrush();                          if ((bool)value == false)             {                 temp.Color = Colors.Black;             }             else             {                 temp.Color = Color.FromArgb(0xFF, 0x46, 0x82, 0xB4);             }             return temp;         }         publicobject ConvertBack(object value, Type targetType, object parameter, CultureInfo language)         {             thrownewNotImplementedException();         }

            


    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 4:00 AM
  • put it as a sample and attach please. it will be easier to debug

    All your questions about windows phone ends here http://howtowindowsphone.com

    Wednesday, August 14, 2013 4:04 AM
  • what i observed is.. foreground color will update correctly only when i go to other page and come back to same page. i wanted immediate reflect when i check/uncheck an item in the list.


    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 4:28 AM
  • You haven't implemented Inotifypropertychanged on your property. have you?

    All your questions about windows phone ends here http://howtowindowsphone.com

    Wednesday, August 14, 2013 4:32 AM
  • I did. Because with the same variable 'IsChecked' i binded to visibility property of the textblock property it is reflecting immediately.

    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 4:48 AM
  • Please put your code in a small project and attach it here.

    All your questions about windows phone ends here http://howtowindowsphone.com

    Wednesday, August 14, 2013 5:02 AM
  • I did silly mistake in my view model.

    i am using open source BindableBase instead of Inotifypropertychanged implemenatation.

    I wrote my property like

    privatebool _isChecked;         publicbool IsChecked         {             get             {                 return _isChecked;             }             set             {

    _isChecked = value; //this causing the mistake. because this line of code, it is not sending the notification in SetProperty.                 SetProperty(ref _isChecked, value);             }         }

      thank you Jebarson for your time.


    Windows Desktop, Windows Phone developer.

    Wednesday, August 14, 2013 11:57 AM