Monday, October 1, 2012

View not binding [closed]

View not binding [closed]

What I hate about Silverlight MVVM is the hit and miss debugging abilities and lack of any RELIABLE way to approach debugging.

I have just broken out all my DataServices out of my ViewModel. Makes sense and its what I want to do. I have dutifully crafted my view separately in Blend. I have built the VM and quietly gloat to myself as I watch the collections getting filled from RIA services. Next step = wire up the Viewmodel locator and we are good to go. NOT as the case may be.

I then watch the view model locator fire up the view model - all collections still getting filled..... but NO DATA showing in the View. Impossible i hear you say. Must be a minor binding issue, so fire up SL5 nice new XAML debugger and see whats cooking. To my horror I realize that the breakpoints arent getting hit... and that was my last bullet. ALL properties are raising propertychanged events correctly. What do I do now?

The ViewModel IS being fired and Populated with data. The binding syntax IS CORRECT in the view but NOTHING will bind.

I think this may be greg's example Xaml of the problem so have moved it from his followup "answer":

<navigation:Page x:Class="PropertyMan.Views.PropertyManHomeView"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"              mc:Ignorable="d"              xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"              d:DesignWidth="640"              d:DesignHeight="480"              Title="Home Page"              xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"              xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"              xmlns:propmancontrols='clr-namespace:PropertyMan.Controls'                              DataContext='{Binding HomePageViewModel,Source={StaticResource Locator}}'>  <Grid x:Name="LayoutRoot">      <Grid.RowDefinitions>         <RowDefinition Height='35' />         <RowDefinition Height='30' />         <RowDefinition Height='30' />         <RowDefinition Height='25' />     </Grid.RowDefinitions>      <Grid.ColumnDefinitions>         <ColumnDefinition Width='180' />         <ColumnDefinition Width='*' />     </Grid.ColumnDefinitions>      <sdk:AutoCompleteBox Grid.Column='1'                          x:Name='acAutoCompleteBox'                          ItemsSource='{Binding Structures}'                          IsTextCompletionEnabled='False'                          FilterMode='StartsWith'                          ValueMemberPath='StructureName'                          Width='Auto'                          Margin='5'                          Height='25'                          VerticalAlignment='Top'>         <sdk:AutoCompleteBox.ItemTemplate>             <DataTemplate>                 <TextBlock Text='{Binding StructureName}'></TextBlock>             </DataTemplate>         </sdk:AutoCompleteBox.ItemTemplate>     </sdk:AutoCompleteBox>     <StackPanel Grid.Column='1'                 Grid.Row='3'                 Orientation='Vertical'>         <Border Style='{StaticResource PropMan.BorderHeader.Blue}'                 Grid.ColumnSpan='4'>             <StackPanel Orientation='Horizontal'>                 <TextBlock x:Name="tbHeader"                             Style='{StaticResource PropMan.TextBlockHeader.Blue}'                            Text="{Binding OwnerListCountHeader}" />                 <HyperlinkButton Content='Email this Group'                                  VerticalAlignment='Center'                                  Margin='50,0,0,0'>                 </HyperlinkButton>             </StackPanel>         </Border>         <Border Grid.Column='0'                 Grid.Row='1'                 Style='{StaticResource PropMan.BlueBackGround.BorderSideBar}'                 Grid.RowSpan='2'>         </Border>         <toolkit:Accordion x:Name='OwnersList'                            HorizontalAlignment='Left'                            Background='#FF0097fc'                            SelectionMode='ZeroOrOne'                            Grid.Column='1'                            Grid.Row='1'>             <toolkit:Accordion.ItemTemplate>                 <DataTemplate>                     <TextBlock Text='{Binding}'                                Style='{StaticResource PropMan.TextBlockHeader.Blue}'></TextBlock>                 </DataTemplate>             </toolkit:Accordion.ItemTemplate>             <toolkit:Accordion.ContentTemplate>                 <DataTemplate>                     <Grid x:Name='UserSummary'                           Width='250'>                         <Grid.RowDefinitions>                             <RowDefinition Height='25'></RowDefinition>                             <RowDefinition Height='25'></RowDefinition>                             <RowDefinition Height='25'></RowDefinition>                         </Grid.RowDefinitions>                          <Grid.ColumnDefinitions>                             <ColumnDefinition Width='10'></ColumnDefinition>                             <ColumnDefinition x:Name='Label'                                               Width='80'></ColumnDefinition>                             <ColumnDefinition x:Name='Value'                                               Width='80'></ColumnDefinition>                             <ColumnDefinition x:Name='Hyperlinks'                                               Width='80'></ColumnDefinition>                         </Grid.ColumnDefinitions>                     </Grid>                 </DataTemplate>             </toolkit:Accordion.ContentTemplate>         </toolkit:Accordion>     </StackPanel> </Grid> 

And the ViewModelLocator

using System.ComponentModel; namespace PropertyMan.ViewModels { public class ViewModelLocator {     private readonly ServiceProviderBase _sp;      public ViewModelLocator()     {         if (DesignerProperties.IsInDesignTool)             return;          _sp = ServiceProviderBase.Instance;          HomePageVM = new HomePageViewModel(_sp.OwnerDataService, _sp.StructureDataService);      }      public HomePageViewModel HomePageVM { get; set; } } 

}


<navigation:Page x:Class="PropertyMan.Views.PropertyManHomeView"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"              mc:Ignorable="d"              xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"              d:DesignWidth="640"              d:DesignHeight="480"              Title="Home Page"              xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"              xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"              xmlns:propmancontrols='clr-namespace:PropertyMan.Controls'                              DataContext='{Binding HomePageViewModel,Source={StaticResource Locator}}'>  <Grid x:Name="LayoutRoot">     <Grid.RowDefinitions>         <RowDefinition Height='35' />         <RowDefinition Height='30' />         <RowDefinition Height='30' />         <RowDefinition Height='25' />      </Grid.RowDefinitions>     <Grid.ColumnDefinitions>         <ColumnDefinition Width='180' />         <ColumnDefinition Width='*' />     </Grid.ColumnDefinitions>      <sdk:AutoCompleteBox Grid.Column='1'                          x:Name='acAutoCompleteBox'                          ItemsSource='{Binding Structures}'                          IsTextCompletionEnabled='False'                          FilterMode='StartsWith'                          ValueMemberPath='StructureName'                          Width='Auto'                          Margin='5'                          Height='25'                          VerticalAlignment='Top'>         <sdk:AutoCompleteBox.ItemTemplate>             <DataTemplate>                 <TextBlock Text='{Binding StructureName}'></TextBlock>             </DataTemplate>         </sdk:AutoCompleteBox.ItemTemplate>     </sdk:AutoCompleteBox>     <StackPanel Grid.Column='1'                 Grid.Row='3'                 Orientation='Vertical'>         <Border Style='{StaticResource PropMan.BorderHeader.Blue}'                 Grid.ColumnSpan='4'>             <StackPanel Orientation='Horizontal'>                 <TextBlock x:Name="tbHeader"                             Style='{StaticResource PropMan.TextBlockHeader.Blue}'                            Text="{Binding OwnerListCountHeader}" />                 <HyperlinkButton Content='Email this Group'                                  VerticalAlignment='Center'                                  Margin='50,0,0,0'></HyperlinkButton>             </StackPanel>         </Border>         <Border Grid.Column='0'                 Grid.Row='1'                 Style='{StaticResource PropMan.BlueBackGround.BorderSideBar}'                 Grid.RowSpan='2'>         </Border>         <toolkit:Accordion x:Name='OwnersList'                            HorizontalAlignment='Left'                            Background='#FF0097fc'                            SelectionMode='ZeroOrOne'                            Grid.Column='1'                            Grid.Row='1'>             <toolkit:Accordion.ItemTemplate>                 <DataTemplate>                     <TextBlock Text='{Binding}'                                Style='{StaticResource PropMan.TextBlockHeader.Blue}'></TextBlock>                 </DataTemplate>             </toolkit:Accordion.ItemTemplate>             <toolkit:Accordion.ContentTemplate>                 <DataTemplate>                     <Grid x:Name='UserSummary'                           Width='250'>                         <Grid.RowDefinitions>                             <RowDefinition Height='25'></RowDefinition>                             <RowDefinition Height='25'></RowDefinition>                             <RowDefinition Height='25'></RowDefinition>                         </Grid.RowDefinitions>                          <Grid.ColumnDefinitions>                             <ColumnDefinition Width='10'></ColumnDefinition>                             <ColumnDefinition x:Name='Label'                                               Width='80'></ColumnDefinition>                             <ColumnDefinition x:Name='Value'                                               Width='80'></ColumnDefinition>                             <ColumnDefinition x:Name='Hyperlinks'                                               Width='80'></ColumnDefinition>                         </Grid.ColumnDefinitions>                     </Grid>                  </DataTemplate>             </toolkit:Accordion.ContentTemplate>         </toolkit:Accordion>      </StackPanel> </Grid> 


I saw one of John Papa's videos (pdc09) where he mentions that sometimes data is returned on a different thread to the UI and everything effectively "disappears". This is most likely what is happening in my case, and I dont have the knowledge yet to deal with UI threading. I have scrapped the approach I was using and I am going to try PRISM and dynamically load views into the UI.

No Answer and comments so far




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog