I am new to UWP and C# but I have been tasked with creating a UI that is created dynamically based on an XML file that is read in.
I am having trouble updating values that are nested inside an ObservableCollection.
The current structure uses StackPanels as a container to add UI elements to. The heirarchy looks like this when the elements are created.
StackPanel = Outermost container panel
-StackPanel = Section Stack panel :implements ObservableCollection
--StackPanel = Entry container panel :implements INotifyPropertyChanged
---StackPanel = Entry inner Wrapper panel :implements INotifyPropertyChanged
---- This is where the UI elements like textboxes live
---- TextBox
---- TextBox
I need extract the values of the TextBoxes but they don't ever update from their original value.
I am having trouble finding documentation that points to a good way of doing this kind of thing (usually means it shouldn't really be done haaa) any input would be much appreciated.
You need to do the following:
Read the data from your xml to your ObservableCollection to build a data as base data structure.
Use binding to bind it to your UI elements from your ObservableCollection. By the way, as Peter mentioned, make sure you've already made it twoway binding, in that way the changes from your UI will reflect the data store in memory
Use some ways(for example use a button) to save changes from your UI and then update and save the data in memory to your original xml file.
Some documention can be found from the following:
https://learn.microsoft.com/en-us/windows/uwp/data-binding/data-binding-quickstart
Code Sample:https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XmlDocument
I ended up using this link to solve my problem.
http://www.teixeira-soft.com/bluescreen/2016/03/23/c-how-to-dinamicaly-select-a-datatemplate-for-each-item-in-a-list/
Related
I am trying to connect a class called Engine with XAML elements, to be more specific I have a LevelWindow.xaml where a grid exists. I want to split that grid (in rows and columns ) from Engine class, the split code exists, but when the programs is running Engine is not changing grid from LevelWindow .... I tryed to semi-use bindings, but i cant find any way to Bind the GRID .... some sugestions ?
Engine
If you absolutely want to use your existing splitting code and that it doesn't support binding and/or notify property changed, you can perhaps find some way to perform what you want using a ContentControl instead of your Grid in your xaml file.
Then Bind the contentControl content property to a grid that you instantiate in your Engine (thus you can access and modify it's inner properties like grid column/rows).
Yet it's quite horrible to perform graphic control instantiation in your business class...
Link to MSDN contentcontrol :
https://msdn.microsoft.com/fr-fr/library/system.windows.controls.contentcontrol(v=vs.110).aspx
I want to display multiple columns (2) and multiple rows. Data consists of Image and label.
Can anyone suggest a way todo it or provide a sample code. I find it challenging as to know, how to bind the data with multiple rows.
I do not have any code to show as I am not able to come up with anything close to what I want to acheive.
You could consider the RepeaterView control (https://github.com/XLabs/Xamarin-Forms-Labs/wiki/RepeaterView) that allows you to bind a control template (e.g. consisting of an Image and Label) to a set of objects as bound or set to the ItemsSource property - it will then create an instance of the control template for every item in the collection, and any binding references within the control template will relate to the individual items in the collection. This is easy to include in your project in isolation.
Alternatively if your requirements are more involved I would recommend the free DevExpress grid component (https://components.xamarin.com/view/devexpress-grid).
I have a listbox that is databound to a List with a bindingsource, what I would like to obtain is that the listbox only shows certain object properties like for example firstName,lastName instead of firstName,lastName,Address,Country,...
How could I manage this?
I'm using winforms.
What about create another type which will be your exact view model and use list of this type?
my last project was a big project in winforms,and i was told that the data bound controls effectively reduce the overall performance of the application.
so the whole group had to work programmatically when adding data to a control,let it be datagrid,combo box,or any other windows control.
i would suggest you do the same too,Adding data to your Controls using code.that way you also decide what you want your clients to see and whatnot.
i would also suggest you take a look here :
how-might-i-add-an-item-to-a-listbox
I have a C# CLI program that scans for missing Windows updates and writes them to command line or serializes them to XML depending on the flag passed in. I'm trying to build a WPF component to this but am unsure of a few things. Specifically I'd like to write all missing updates to a grid in the center of my WPF main window. The appearance would be something like this (with gridlines between the fields):
NAME SEVERITY DETECTED
Security Update for Windows 7 (KB1234567) Important 3/9/2014
Security Update for Windows 7 (KB7654321) Critical 3/9/2014
My specific questions:
What type of control would I need to add to the window to house this data?
How do I send the data (detected missing update names and properties) to the grid for display?
How can I set the control so that it is collapsed (or invisible) when no missing updates are detected?
Will I need to add a scrollbar to the grid or will one display automatically?
Apologies for the simple questions. I'm really just looking for some examples to get started, and I haven't been able to find anything thus far that meets my needs.
What type of control would I need to add to the window to house this
data?
DataGrid control is what you are looking for.
How do I send the data (detected missing update names and properties)
to the grid for display?
Bind ItemsSourceof DataGrid to ObservableCollection<T> where T will be class containing data with properties Name, Severity and Detected.
How can I set the control so that it is collapsed (or invisible) when
no missing updates are detected?
Add a DataTrigger to check if ItemsSource collection contains no data, collapse the visibility.
Will I need to add a scrollbar to the grid or will one display
automatically?
DataGrid internally use ScrollViewer. No need to add explicitly.
Refer to the dataGrid samples here and here.
As an alternative DataGrid can offer ListView control, it will be little "easier" than the DataGrid, he also supports the ability to sort columns. For him also need to bind a ItemsSource collection to display:
The ListView control provides the infrastructure to display a set of data items in different layouts or views. For example, a user may want to display data items in a table and also to sort its columns.
Example in MSDN.
Little add some notes to the wonderful answer of #RohitVats, all that has been said about DataGrid also applies to ListView:
How can I set the control so that it is collapsed (or invisible) when no missing updates are detected?
In this situation, I advise you to adhere to the principle of MVVM. Use Binding and Commands to create an independent application. You want to create property (for example IsEnabled) in Model / ViewModel and use bindings to set them in the View, in order to avoid apply directly to the Control. WinForms style app or "regular" applications creates a strong connection between logic and UI, which subsequently impedes further change and application maintenance.
The topic says it all essentially. I need to have my live tiles display various types of data, such as lists, charts, etc, and have them auto update by pulling data from web service. I need to know how can I host listview or a chart control inside live tile control.
My current setup is a Telerik RadTileList that I add dynamically to in code behind my custom class that inherits from Telerik LiveTile, I specify my webservice that for example can get back a list object with a couple of fields.
I know I can display them directly in my LiveTile's ClientTemplate referencing them with #= data.FieldName #, but I want the data to be displayed by an imbeded Telerik ListView control that I can hopefully can insert somehow inside my livetile and have the results of the webservice bind to it.
If I'm over-thinking it, or if the architecture can be improved to achieve the same I am open for suggestions as well as long as I can achieve the end result described above.
Any suggestions would be appreciated.
I don't think you can do this. Live tiles only take HTML: http://www.telerik.com/help/aspnet-ajax/tilelist-server-side-tile-object.html. Here is what it says for the ClientTemplate: Gets/sets the HTML template that will be instantiated in the tile after live data request..
I think that you could get the data, bind it to a hidden listview or chart and move the bound listview/chart in the DOM to inside the tile, via the events and API it has:
http://www.telerik.com/help/aspnet-ajax/tilelist-tiles-client-side-events-livetile-onclienttemplatedatabound.html
http://www.telerik.com/help/aspnet-ajax/tilelist-client-side-tile-api.html
but I am not sure if any other functionality of the controls you move will work after that, since you will only be moving their HTML.
You can generate lists with JavaScript if that will work for you and use set_html()...