Adding dynamic content to a Data Grid in a dynamically created Tab - c#

In C# WPF MVVM I have implemented a TabControl with observable collection and every time I click a certain button, a new tab is created. Inside every tab I want to have a data grid, so I added a data grind into a TabControl.ContentTemplate. Now I want to fill the data grid dynamically. Depending on which tab the data grid is in, I want to bind its ItemsSource to a certain list. So every tab has a data grid with a list of elements, but these elements are different depending on which tab the data grid is in. How can I make this binding?
I thought about extending the TabItem with a list of elements I want data grid to contain, but I do not know how to access the TabItem to which a specific data grid belongs to using XAML.
How can this be done?

I ended up adding a new UserControl and a corresponding ViewModel for it, and then added the crated user control inside the DataTemplate tag.

Related

Programmatically create table with clickable and expandable content in WPF

This is what I desire to create:
As you see I need to create table like control with images and clickable cells. When you click on an arrow on the left it expands its' content and content contains some more additional table like controls with data. Also when user clicks on a Star I need to add this event to Favorites list and etc.
Currently, for each data row I'm thinking of programmatically creating accordion item with Grid in header for images and cells and other Grids for the content.
What is the best and easier way to achieve this task? What controls should I use? I need some suggestions, as I'm new to WPF.
WPF DataGrid can show RowDetails. Customize them with RowDetailsTemplate property and manage their visibility with RowDetailsVisibilityMode property

Add usercontrols dynamically inside a GridView

Here's my problem. I am trying to add usercontrols dynamically to different rows of a GridView.
Let me explain the scenario further. Let's say, I have a page where the user can place orders for different kinds of items. The order form for each item is different in layout and code, and has its own usercontrol. There is an "Add More" button, which lets the user add an extra row to the GridView, while the kind of form that gets appended is selected by the dropdown list (see picture below).
What I am trying to do is - have a separate UserControl for each one of these forms, and then have the UserControl added (or maybe I should say "bound") to the GridView. Every time a new row is added, I plan to re-bind the GridView, including rows from above, to maintain all the rows.
The problem is - the main page cannot know what fields there will be inside each individual UserControl (they can be anything, really, and down the road, newer UCs could be added). So my main question is - how do I bind the data to the GridView, when I do not know what to bind? Is there any way to bind the data from inside each UserControl itself?
I hope my problem and question are clear enough. Thanks for helping.

Manually opening a ListPicker

I have a ListPicker (from Telerik's Rad Controls suite) in PopUp Mode (with around 200 elements) with its visibility set to Collapsed. I want to open when it when I press a button, instead of when I press the control itself.
Basically I'm asking if there's any way of programatically opening a UI element in Windows Phone (something like Control.Open() in the code behind).
The context for my question is the following:
as you know, the selected item of a list picker is displayed in the page containing the control.
users can click on this item to activate the control.
I want to display only one of the properties in the page containing the control (for example MyObject.Name instead of the entire MyObject), but I can't do this because the SelectedItem and ItemsSource need to be of the same type.
I'm thinking of styling a button to look identical to the ListPicker's selected item.
I need to open the ListPicker programatically when I click on the button, I'll bind the button's text to MyObject.Name
Alternatively, I could just do a data template for the way the list picker is displayed, but I'm not convinced it's possible.
Found the answer. It seems Telerik's List Picker allows you to set both an ItemTemplate for displaying items in the actual page, and a PopupItemTemplate for displaying items when the list is expanded. Both are Data Templates, so you can use Binding for values.

Refresh ItemsSource from other window

I have a application which has a parent window with some menus on it ,when the menu clicks corresponding usercontrol is loaded inside the parent window as child.The parent window supports many usercontrols on each menu click ,the usercontrols are docked into the parent window. I have a usercontrol namely Items master from which the user can add items and save into database, I have another usercontrol which has a datagrid with a Combobox column for selectiong Items .The both user controls are docked on the parent window .When I add an Item into the Item master but that product is not available on the datagrid .How to refresh the items source of the datagrid combobox column when a new product is added ?
The quick answer is: use something like an event-aggregator to pass messages around the system when data is altered, so that each individual screen can re-load their respective data. The more important part is in designing and structuring you application to allow views to access the common data effectively. Look into something like MVVM for UI design.

Insert Data Into Listview And Save To SQL Server

am using C#, VS-2005
am new for listview Control in VS-2005. I know how to Insert Records into Listview by typing on Outer Textbox.
But don't know how to directly insert Records on Empty ListView control as it not Focus It's Self.
If any other way or is it possible to insert data directly to ListView Control then Please provide me some code or guide me please.
If you refer to WinForms, see the System.Windows.Forms.ListViewItem Class,
it Represents an item in a ListView control.
ListViewItem class defines the appearance, behavior, and data associated with an item that is displayed in the ListView control. ListViewItem objects can be displayed in the ListView control in one of four different views.
From the example on the same page (see the full example using the ref above):
ListView listView1 = new ListView();
...
ListViewItem item1 = new ListViewItem("item1",0);
...
listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});
It sounds like you want a grid control rather than a Listview control. In my experience, Listview controls are primarily read-only and grids are editable. Have you considered using a grid?

Categories

Resources