I am about to begin a major step in my app by taking images I post on my website and having the phone retrieve these images and dynamically add them to a listbox. That listbox will contain a thumbnail of the image, as well as the time it was posted. If a user clicks on the image, they will be taken to another page where they can either download it to the phone or share it to someone.
However, as with any absolute beginner, I am seeking tutorials on how to do this.
I have found two:
http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx
Windows Phone 7: Making ListBox items change dynamically
I'll make some mock code up in an effort to help understand my approach on this:
Have a listbox (name: photosfromsite)
Aim is to have ListBoxItems as individual photos from the site. How to populate these dynamically is yet to be done. How?
Be able to pass ListBoxItem name/identifier/etc to pass the image on new page when
clicked (use query during page transition?)
Have website set with photos.
Do an asynch call upon application launch to retrieve these images.Calling maybe 10 at
a time?
Page1 XAML:
<Grid x:Name="layoutgrid">
<StackPanel x:Name="panelforlistbox">
<ListBox x:Name="photosfromsite">
<ListBox.ItemTemplate>
<ListBoxItem>
<Image Source="http://www.thewebsite.com/Image1.jpg>
</ListBoxItem>
<ListBoxItem>
<Image Source="http://www.thewebsite.com/Image2.jpg>
</ListBoxItem>
......
......
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
Page1 C#:
//Some event handler to requisition the website for the images placed
//Some code to grab {get, set} the date and time
//Some code to generate a new listbox item in light of this.
//Some event handler for getting the updated list, if not already updated.
//Some event handler to signify when a user clicked on a listboxitem and to
//pull that info to a new page.
I realize I am missing a large portion of this code, but I think I have a somewhat passable framework in mind of what I need to do?
Any help is always appreciated. I've picked up C# for the first time a couple months ago, and slowly I've been learning a lot about it. This seems to be the only major thing in my way before my app is done, and I just want to make sure I get it right!
And to make sure no ambiguity exists in the claim about what my question is -- Are these suitable tutorials or is there somewhere with a step-by-step instruction (preferably video) of how to accomplish exactly what I am trying to do. If not, can example code be written or pasted?
Have you considered how the website will maintain a list of its images? Or are you going to scrape the HTML for them?
Are they going to be FTP'd to the site or will there be some form of DB that contains a list of them?
A webservice could then be added to the site that returns a list of all images that would then be the datasource of the list box. A convertor could be used to modify the image file name to include the full path to where the image is? I'm guessing the webservice could even be used to create the thumbnails and send them to the phone, or the phone could retrieve them and create the thumbnail.
It would be worth considering the bandwidth requirements of moving large images images about.
Related
Writing a fairly simple app with c#/wpf.
When opening a second window there is a brief flicker or flash.
Extensive googling says that this caused by screen repainting, so not much I can do about that.
(I haven't included any code because it seems this problem is well known and something most people 'learn to live with')
So, I thought, why not put all the XAML in one file with each page within its own grid that I can hide/show with visibility.visible or visibility.collapsed etc.
Works nicely (apart from a very slight delay - less than 1/2 second - the first time i show the second window grid), but I'm unhappy at the idea of containing all the code behind in a single page. (for what its worth, i'm told that compiler see's it all as one file anyway but ... )
Is there a way I can create separate 'code behind files for each 'windows' (in reality a XAML Grid) functionality whilst linking them all to the same Xaml File?
(I have a horrible feeling having typed this that the answer is obvious and I should already know it ...)
Thanx
If I understand you correctly, you just need to create a new Control Class-Code Behind pair for each 'window grid'. This is done in VS by clicking Add-Create Element-User Control (of name UserControl1.xaml, rename it to something Like YourControl.xaml) in Solution Explorer (I think you already know all this, but just in case).
Now, if there is no specific requirement for the control to be of type Grid, you can use it as it is:
<MainWindow>
<Grid>
<YourControlNumberOne />
<YourControlNumberTwo />
<YourControlNumberThree />
<Grid/>
</MainWindow>
If you specifically need Grid-based control, just change the base class of YourControl to Grid, and change the topmost XAML element in the associated XAML file to Grid.
I'm creating a simple UWP application for myself and stuck with lack of understanding of how binding and all that stuff works. Don't know how to explain it better So I created a simple example: https://gist.github.com/anonymous/744dc688d0663a3c14b7a2fc424316f8
The program has a list of selectable items on main screen. I can select several items, press a button and program will show new floating panel, with selected items (And I do further management of these items in my original program). I want this panel to be separate control because my MainPage is already overfilled with code.
The problem is. When I click on the button first time - it works as I expect. But then, when I change selected items and click button again, it shows panel with items from first selection.
My question is - how to do make it work? I have a feeling that it has to be something with INotifyPropertyChanged but cannot understand it.
And I also would be glad to hear the overall recommendations. I'm not c# developer. I'm actually sys. admin but I know a little of python and I learned Delphi 7 in university. So I'm kind of learning c# in process of creation of this application.
UPD: If I change line 28 of SelectedItemsView.xaml from
ItemsSource="{x:Bind SelectedItems}"
To
ItemsSource="{Binding SelectedItems, ElementName=SelectedItemsViewRoot}"
(and add x:Name="SelectedItemsViewRoot" to user control attributes). It works as needed. So new question arrives - is this correct way to do this? I though that Binding is kind of legacy and x:Bind is newer approach that should be used in new apps.
It's ok to use {Binding}, but if you want to stick with {x:Bind}, you can do this with OneWay mode (instead of default OneTime). For example: {x:Bind SelectedItems, Mode=OneWay}.
I strongly encourage you to read these two official tutorials:
Data binding overview and Data binding in depth.
In short, {Binding} is not legacy. It's actually a bit more flexible, but it's performed in runtime, while {x:Bind} is perfmormed at compile time, thus a bit more performant.
I'm new to WPF, and I wish to know, if the following is possible.
I have two WPF pages "Page_Parts" and "Page_Parts_Edit". Page_Parts has a link to call Page_Parts_Edit, and its contents of the entire page are displayed within Page_Parts.
Page_Parts contains a datagrid with all the parts in the system. I need to be able to click on a row within the datagrid and pass the selected row data to a textbox within the child page "Page_Parts_Edit". In essence allowing the user to select the part details from a given selection.
I'm able to do a similar approach when both objects are contained within the same WPF page, in the following manner:
<TextBox x:Name="TextPartNumber" Text="{Binding ElementName=ListViewPart, Path=SelectedItem.PartNumber}" Width="150" />
However, I'm not able to use the same approach when the datagrid is part of one page and the textbox is part of a different page.
Perhaps creating an array of strings, that the datagrid selected row updates which is linked to a DynamicResource, then bind the DynamicResource to the textboxes on the other page. Is that possible?
I'm open to any other suggestions.
Hope my question is clear.
Thanks in advance.
Alain
The problem I'm facing is that, I'm unable to access a control(button) which is in the MenuPanoramaPage.xaml from another page which is MyProfile.xaml.
I wanted to change the content within the button when I select the radio button which is in the MyProfile.xaml. How could I make this?
I tried using this within the button tag in xaml:
x:FieldModifier="public"
But it didn't work out. How can I work on this?
Thanks in advance.
I suggest you to use MVVM Pattern in which use can handle these kind of problems like handling data of one page from other page.
I give you a simple scenario :-
Suppose you want to change the content of a button that is on another page then what you have done basically is.
Some Points :-
1- > Define a string property in viewmodel of the page that contain button. and bind this property to the content property of the button.
2 -> So suppose you want to change it from other page then all you have to do is send a message from another page to change this property. And it will be automatically updated on button(you will get it after some example setup).
3 -> It is not related to some simple string contents. You handle whole data that will be displayed on that page and other View related properties too.(Basically MVVM is much more powerful than you can thought of).
4 -> Last point If you want to make a quality Windows Phone app then MVVM pattern is a good fit.
Links :-
How to implement MVVM in Windows Phone
Basic one from Channel9
What actually MVVM is ?
Explore those. You will not regret. Cheers :)
Sorry, but this is not possible. You only have direct access to the controls on the page you are on. In this case you can only change the controls in MyProfile.xaml.
But what you could do is sending an event or message (if you are using mvvm) to the MenuPanoramaPage.xaml / ViewModel.
I know that you aren't supposed to add more than 7 items to a pivot control, but it's just dead easy to use.
I wasn't even running into problems until now: I got a pivot item template which renders articles (Say, date, title, content). I'm using a pivot because when flicking the article I want to go the next/previous one. However, after a number of flicks (~50, little abyssmal) I get an OutOfMemoryException. The memory usage suggests, that PivotItem contents are generated on the fly when first accessed, but then they aren't released.
I could hook into UnloadedPivotItem/LoadedPivotItem (works well for image viewing and the Source property) and clear the visual trees, but that would mean that I had to generate the contents for every view model "by hand".
So: Is there any possible way to specify how big that cache should be? Or at least a sane way to regenerate the PivotItem content from a given ViewModel?
I would recommend using Telerik's SlideView control. In my mind, there is no reason to not use Telerik's control (I do not work for, nor endorsed by Telerik). You can download the Telerik Examples app from the store to see it being used. This control is exactly what you need. It works just like any other ItemsControl would. You set the ItemsSource and ItemTemplate.
<telerikPrimitives:RadSlideView ItemsSource="{Binding Articles}"
IsLoopingEnabled="False" <!-- Will NOT go back to the beginning -->
ItemRealizationMode="ViewportItem">
<telerikPrimitives:RadSlideView.ItemTemplate>
<DataTemplate>
<Grid Margin="12,0,0,0">
<!-- Content ->
</Grid>
</DataTemplate>
</telerikPrimitives:RadSlideView.ItemTemplate>
</telerikPrimitives:RadSlideView>