[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Windows Mopbile 7 - Update controls after data change

Posted on 2011-10-06
8
Medium Priority
?
194 Views
Last Modified: 2013-12-27
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
Comment
Question by:ChrisMDrew
  • 5
  • 3
8 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 36924960
Reset the Data by settings the ItemsSource to your "Jobs"
0
 

Author Comment

by:ChrisMDrew
ID: 36925304
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
 
LVL 48

Expert Comment

by:Mikal613
ID: 36925385
either a) Set the listbox itemssource to null and then to your list
or Call Lst.UpdateLayout() af the Setting of the datsoource
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 

Author Comment

by:ChrisMDrew
ID: 36942775
Still doesn't seem to do anything - any other suggestions?
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 2000 total points
ID: 36942784
Can you do both?

Reset your items in  the Listbox
and then UpdateLayout()

Thanks..
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 36958743
I take it, it worked :)
0
 

Author Comment

by:ChrisMDrew
ID: 36962423
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
 
LVL 48

Expert Comment

by:Mikal613
ID: 36974764
Are the file names correct for the image?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question