Reputation: 23
I have built a view model and the listbox binds to the ObervableCollection, but a textbox I am using for a temp url wont bind and return data. I am not getting any errors either on compile or run
ViewModel:
public class HomepageModel:INotifyPropertyChanged
{
public TextBlock bgrImg{get;set;}
public ObservableCollection<MenuItem> menu {get; private set;}
public HomepageModel()
{
this.menu = new ObservableCollection<MenuItem>();
}
public void Load()
{
bgrImg = new TextBlock();
bgrImg.Text = "/Windows7MobileClient;component/Images/Desert.jpg";
//bgrImg = ;
menu.Add(new MenuItem("Feed",""));
menu.Add(new MenuItem("Messages",""));
menu.Add(new MenuItem("Media",""));
menu.Add(new MenuItem("Favourites",""));
menu.Add(new MenuItem("Freinds",""));
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Homepage.xaml
<controls:PanoramaItem Header="menu">
<Grid>
<TextBlock Text="{Binding bgrImg}"/>
<ListBox x:Name="FirstListBox" Margin="0,0,-12,0" ItemsSource="{Binding menu}" MouseLeftButtonUp="FirstListBox_MouseLeftButtonUp" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding label}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</controls:PanoramaItem>
I eventual want to use the string for the panorama background image. Sorry if this seems realy obviously simply.
Chris
Upvotes: 0
Views: 2509
Reputation: 2730
One more thing I noticed: You are trying to Bind TextBlock to a string Property:
public TextBlock bgrImg{get;set;}
<TextBlock Text="{Binding bgrImg}"/>
Change the type of the property to string:
public string bgrImg{get;set;}
<TextBlock Text="{Binding bgrImg}"/>
Upvotes: 1
Reputation: 54600
You need to call NotifyPropertyChanged() in your setters for the items you wish to bind to.
Upvotes: 3