• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Windows Mopbile 7 - Update controls after data change

I have a listbox which is bound to a Job object.  A button on the form marks the job as complete.  There are a number of fields which are displayed if the job is complete but hidden otherwise.

I am using DataBinding to set the visibility of these controls as required as I am displaying a list of jobs within a listbox and am only marking a specific job as complete.  I use a converter to set the visibility of the controls based on the Job property 'IsCompllete'

My question is - how do I force a refresh of the Job when I click the Complete button - in old Windows forms I would be doing a DataBind()?
0
ChrisMDrew
Asked:
ChrisMDrew
  • 5
  • 3
1 Solution
 
Mikal613Commented:
Reset the Data by settings the ItemsSource to your "Jobs"
0
 
ChrisMDrewAuthor Commented:
My DataSource is set at the ListBox level and contains a number of jobs.  When I click COMPLETE I read the job, mark it as complete, update my underlying Job object and then set the datasource for the Jobs List again - nothing happens...
0
 
Mikal613Commented:
either a) Set the listbox itemssource to null and then to your list
or Call Lst.UpdateLayout() af the Setting of the datsoource
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ChrisMDrewAuthor Commented:
Still doesn't seem to do anything - any other suggestions?
0
 
Mikal613Commented:
Can you do both?

Reset your items in  the Listbox
and then UpdateLayout()

Thanks..
0
 
Mikal613Commented:
I take it, it worked :)
0
 
ChrisMDrewAuthor Commented:
Unfortunately I thiought that it had but it hasn't completely.

My list box is defined as :-

<ListBox x:Name="lbJobPictures" Width="450" Height="800">
    <ListBox.ItemTemplate>
      <DataTemplate>
      <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
      <Image Source="{Binding Image}" Width="250" Stretch="Uniform" HorizontalAlignment="Center" />
      <Button Content="Delete" Tag="{Binding fileName}" HorizontalAlignment="Right" VerticalAlignment="Top" Width="180" Name="bnDelete" Click="bnDelete_Click" HorizontalContentAlignment="Center" Margin="20,0,0,0"/>
                                          <TextBlock Text="{Binding fileName}"></TextBlock>
      </StackPanel>
    </DataTemplate>
</ListBox.ItemTemplate>

I want to delete a picture so my code looks like the following button handler:-


                  </ListBox>
 
private void bnDelete_Click(object sender, RoutedEventArgs e)
{
	if (MessageBox.Show("Are you sure that you want to delete this picture?" ,"Confirm Delete" ,MessageBoxButton.OKCancel) == MessageBoxResult.OK)
	{
		// Get the existing dataSource
		JobPhotosList listJobPhotos = (JobPhotosList)lbJobPictures.ItemsSource;
		Button button = sender as Button;
		string fileName = button.Tag as string;
		var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
		if (isoFile.FileExists(fileName))
		{
			isoFile.DeleteFile(fileName);
			_whereabouts.Jobs[_jobIndex].Pictures.Remove(fileName);
			listJobPhotos.DeletePicture(fileName);

			// Update whereabouts
			_whereabouts.SaveToIsolatedStorage();

			// refresh data source
			lbJobPictures.ItemsSource = null;
			lbJobPictures.UpdateLayout();
			lbJobPictures.ItemsSource = _whereabouts.Jobs[_jobIndex].Pictures;
			lbJobPictures.UpdateLayout();
		}
	}
}

Open in new window


The list box does refresh so that if I had 3 pictures and 3 buttons displayed I now see just 2 buttons but no images get displayed - I guess that they need to get refreshed somehow also...
0
 
Mikal613Commented:
Are the file names correct for the image?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now