Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best approach to develop WPF application [closed]

Tags:

c#

wpf

I'd like to create a WPF application and would like some advice on the most appropriate approach.

I want to create an RSS reader that automatically refreshes when a new RSS entry is added. The problem is that I don't want to use traditional controls (listbox/listview) to display the data. I'd like the feed items to appear in panels randomly on the screen. These panels consist of several textblocks. Each panel displays one feed item.

It would look something like this: Concept

This raises several questions:

1: Generate panels completely from code, or use a Custom Control?

I would model a class like a panel as described above. This class manually adds all controls to the form and drops the panel at a random location on the form. When a new RSS entry is added, an instance of this class gets instantiated and passes the rss information as parameters.

On the other hand, it might be better to create an UserControl for this. Is it easy to create this UserControl by code and pass it the parameters in the constructor?

2: Can my data/panel automatically update when a new RSS entry has been added online?

Right now I would refresh everything each (x) seconds and check against a collection of panels if there has to be created a new one. If so, create a new panel and drop it randomly on the form.

Is there a better way of doing this? I can use a local ObservableCollection with databinding that automatically updates a control (listbox, etc) when the collection changes, can this also be done with an online source like an RSS feed?

The most ideal way would be that my application gets notified when a new RSS entry has been added, downloads the last entry and creates a new Panel (trough code or trough a UserControl)

If this is hard thing to accomplish, I'll use the traditional refresh method.

3: Do I have to use DependencyObject/DependencyProperty?

I know DependencyObject & DependencyProperty expose some powerful functionality for UserControls, but I don't really know how to use them. Are they necessary for this kind of application?

4: Do I have to use WCF (Windows Communication Foundation)?


I'm not really experienced with "advanced" WPF stuff like advanced databindings, DependencyObjects and UserControls, but I love to learn!

like image 394
Nick Avatar asked Jul 08 '11 17:07

Nick


People also ask

Is WPF still relevant 2022?

“WPF would be dead in 2022 because Microsoft doesn't need to be promoting non-mobile and non-cloud technology. But WPF might be alive in that sense if it's the best solution for fulfilling specific customer needs today. Therefore, having a hefty desktop application needs to run on Windows 7 PCs with IE 8.

What is WPF being replaced with?

Universal Windows Platform. Both Windows Forms and WPF are old, and Microsoft is pointing developers towards its Universal Windows Platform (UWP) instead.

How do I close an application in WPF?

Use the this. Close() method in the MainWindow. xaml. cs file to close the window.

Does WPF have a future?

This move clearly explains that Microsoft sees a future in WPF and considers it as a UI framework for the . NET platform. Microsoft has really invested a lot in WPF by making it open source and making it work on . NET Core.


1 Answers

I would recommend firstly looking into using the MVVM design pattern, and using an MVVM framework. Secondly, you could achieve this effect using an ItemsControl and use a Canvas as it's ItemsPanel type, then you could use a custom ItemTemplate which renders each data object using a UserControl.

The user control would have a dependency property which is the data item, and you would bind this in the item template declaration.

You could have a model which models each RSS entry (RSSEntry) and perhaps an RSSEntryViewModel which adds the x and y coordinates on the canvas.

Your screen view model would then have an ObservableCollection of RSSViewModel which you would add/delete etc to and the UI would automatically update.

You wouldn't need a service layer if you didnt want to, but as long as your view model retrieves the entries via an abstraction, it should be easy to refactor in the future.

like image 113
devdigital Avatar answered Sep 20 '22 03:09

devdigital