WPF share data between pages - c#

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

Related

Xamarin forms: Display and bind data for list/grid with multiple rows and columns

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).

Screen Reader not reading content of DataGrid from WPF Toolkit

I'm writing a BHO that uses an ElementHost to host a WPF User Control. Within the user control, I have a DataGrid that binds to an Observable Collection. Everything functions fine, except that the content is not being read by screen readers (I'm using NVDA to test, but QA is using JAWS).
I'm restricted from copy & pasting code on a public forum, but I can describe the layout that I'm creating. There are two datagrid. One contains all of the items from the Observable Collection and the other is a subset of the items. Each datagrid is in a separate Tab Item of a TabControl. As I stated, there is an ObservableCollection that holds my business objects. Each object binds to a row in the datagrid. Several of the columns require that I display multiple properties from the business object, so I'm using the DataGridTemplateColumn. Within the CellStyle, I have 3 DataTemplates set up; one for edit, one for add and one for view. The view DataTemplate is exactly the same as the DataGridTemplateColumn.CellTemplate.
One of the columns holds my action buttons. One of the buttons is an edit button which simply applies the edit template to the rows cells. Outside of the datagrid, I have a button that will add a new default item to the ObservableCollection, call UpdateLayout on the datagrid, then set the DataTemplate of the new item to the add template.
There is also a button that will grab information from a remote server, convert it to business objects and add them to the Observable Collection. The datagrid loads the new information with no problems.
When I use the function to pull the objects from the database, none of the information will be read by the screen reader. If I click the edit button, everything is read as expected. After returning to the "view" DataTemplate, everything reads as expected. If I use the Add button, everything reads as expected.
To make this more complicated, if I edit an item in one tab page and get it to be read, then go to the other tab page and come back, it's no longer reading.
I have a feeling that it's related to the how binding and templates interact, but I don't know enough about either to figure out a direction to go in resolving this.
Any help would be appreciated.
EDIT: While I was creating the dummy project to show the issue, I discovered that the problem is not just limited to Template Columns. I created a business object with string properties, created an ObservableCollection with 10 objects in it and bound each property to a DataGridTextColumn, and it only reads the grid name and column index...the contents are never read.

Why Drop down list box in a cell of grid data bound grid is not properly displaying

I am developing a windows application using c#. I use syncfusion's controls instead of visual studios default controls. In my application I am using data bound grid. In this grid I have a cell which has another grid as drop down list. It works fine, but in one situation it is not properly displaying. Situation is:
click in a cell which has grid as list and select its content
instead of clearing content in it directly type a character
list of 4 items get displayed which matched the typed character
now clear content in a cell
now list of all the records get displayed but I can see only one record at a time
It is like list id hiding behind something, I am not getting actually what is happening. Please reply me if you have solution to it. I will provide my code and screen shots if anybody need it.
Thanks
To solve this problem, close and open drop down list

How to implement a customized sortable and expandable list in WPF

I need to implement a list customized like below. You should be able to sort items on a given field by clicking on a header.
A line should also be expandable. When a user clicks on a +, the line should expand and disclose more information under its field2 value.
I have tried to use a ListView in a GridView. For each column, I have defined a template (a template for field1 values with the + on the left, one for field 2 values and one for field 3 values). With this implementation, my problem is "how to expand one line".
I also looked at the ListBox component, but I need to create headers manually and align the content. I also need to sort manually. It doesn't seem to be a good solution to me.
Do you have any better idea, or any advice?
The correct base Control appears to be the DataGrid.
It will provide you with the functionality like sorting on headers, etc.
You will have to modify its ControlTemplate through a style if you want it to look like in the screenshot.
As an inspiration how you could ge the detail expansion, the following article could help you:
Grouping in DataGrid in WPF
You can also consider having a look at third party dataGrids, in case the standard DataGrid doesn't cover all of your needs, but with individual Templating you can get pretty far.
If I understand correctly, by "expand" you mean to show sth under a line (or specifically, a list view item)?
If it is the case, in your data template, add a stackpanel, for instance, and change its Visibility to collaped;
by clicking on the "+" button, change the collaped to visible.
<ListView ...>
<ItemTemplate>
<GridView ...>
<Button Name="ExpandButton Click="OnClick"/>
<StackPane Visibility={Binding SomeProperty} />
<Itemtemplate>
</ListView>
In Onclick, change the SomeProperty=Visibility.Visible. I assume you are comfortable with data binding in WPF.

Master-detail questions

I'm just learning WPF/binding and Entity Framework. Currently I'm working on following:
There is master - detail - detail. I have commission plan, I have commission plan items and each commission plan item has eligible users.
On UI - commission plan object set as a context and I bind all properties. Main detail grid bind to CommissionPlanItems. That works great.
Couple problems I'm trying to solve. Or I guess I'm just looking for general guidence.
1. My CommissionPLanItems have LineNumber property. I don't really need it displayed but I need it populated and I need grid to display items in proper order. I placed button to move row up as a template:
<pre>
<code>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="Button_Click">Move Up</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</code>
</pre>
I can handle that button click and get corresponding object but I have few problems
a. Button displays in new grid row placeholder. How do I prevent it from displaying there?
b. Is there way to automatically "reorder rows?
2. Each commission plan item can have multiple customers associated. How do I make this UI-wise? I was thinking some kind of button in a grid that will bring pop-up modal form where items can be selected.
3. Grid has drop down columns. When they go into "edit" mode - they make row taller. I don't really like that effect. How do I work around it?
For #1: yes it is possible to sort a gridview within WPF but not automatically. For that you may need to use a off-the shelf control from Telerik, Dundas, Infragistics etc. MSDN provides a nice tutorial on how to hook this up yourself via code. http://msdn.microsoft.com/en-us/library/ms745786.aspx
For #2: This depends on how you have your Type defined. You could do this via a tooltip on the cell with a custom datatemplate containing a listbox control applied which shows each person or their information. This could also be handled in a separate user control that could appear when the row is selected. You have a ton of options here. As long as you can get at the data you are golden. Just define what you need to show and anticipate the max number of records being displayed. Obvosuly if every row shows approximatley 10 records a small tooltip may not be the best approach but a larger floating usercontrol may be.
For #3: If you are using a datatemplate for the definition this object you could set MaxHeight or MaxWidth to control the maximum height of the control. This could also be affected by padding of the element so you may want to set the padding="0" (zero)

Categories