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)
Related
I am not sure combobox would be the best vehicle for tackling this problem, but visually it is appealing.
Consider such data as angle -- I could enter its value in radians (single editbox) or in form of degree, minute, second, millisecond (4 editboxes) -- there are other representations, but those two will suffice here. For now I have combobox with mode entries "radians", "DMS" changing mode shows/hides appropriate control.
This approach has two flaws -- it takes a bit more space (for extra combobox with modes), and since each control is different is size everything on right of it moves.
So I am thinking about more direct approach, instead selecting mode, which in turns switches visibility of given control, would it be possible to put each control inside combobox, and combobox would then select that control. The target data would be exactly the same for each row (angle), but each row would have different control, because each row would mean different representation.
Is doable with combobox or am I banging at the wrong door? If combobox is suitable for this task, how to do it?
I was so focused on data binding at the combobox level that I didn't notice that the solution uses the basics of combobox.
So first, for the moment forget about combobox binding to anything -- simply per each row define ComboBoxItem and put any control you like. In effect you will get multiple controls for the same data.
At this point the only missing part is selecting the mode. Since I no longer rely on manually switching visibility of the controls (combobox does it automatically) then I can bind to SelectedIndex and convert it only fly back and forth to mode.
Please note combobox is not bound per se to the actual data (angle in this case).
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
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.
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.
I'm having some trouble coming up with a xaml page that would bind to a keyboard layout displayed on a page. Originally I have an ObservableCollection of rows that contain a KeyboardKey datatypes that specify the width of a button. The collection is bound to a listbox in the xaml. The problem I'm having is that on some keyboards the the height of a key spans two rows, which the xaml listbox does not support. I would like to avoid hard coding a bunch of keys in the xaml. Any thoughts on how to approach this?
You can create you own layout buy inheriting one of container controls and overriding
ArrangeOverride method.
You can find the example here: http://www.wpftutorial.net/CustomLayoutPanel.html
When I was creating the virtual keyboard, I declined automatic layout and put the buttons manually in designer. I think in some cultures it is better to put key rows with horizontal shift and in others it is better to to place buttons under each other. So I have a flexible layout and can quickly edit it in designer.