Does anybody know of a tutorial or sample code on how to create a simple designer control in WPF?
I am trying to write a simple designer in WPF where users can drag and drop data items (charts & lists) on specific points on a page (e.g. Line 3, Coloumn 24).
You can check out this article about a diagram designer in WPF (this is the last part but the entire series if 4 articles long). It's not related to report but might give you a starting point about how to manage items on a surface with drag'n'drop.
Related
Urgent help -
I have to implement Search functionality in WPF windows application. In this application, I have a TreeView control, when the user clicks on any TreeViewnode corresponding Wpf user control will appear in right side with data.
I want to implement search. User can enter any thing into Search textbox and that search term should get highlighted in rightside WPF user control.
How can I implement that?
Is there way to show searched term without hitting database.
Your help is much appreciated.
1) To search any textual item in a WPF view you would have get into the logical and visual tree to get children.
2) Identify the textual properties of each child such as .Text, .Content, .Header.
if an item that carries texual info is found then use
if (<value> is string && ((string)<value>).Contains(searchString))
{
/// Implement step 3 and 4 below.
}
3) Use child.Focus() and child.BringIntoView() calls if one by one search is intended. Otherwise skip to step 4.
4) Use adorners to highlight such item.
Sadly this search will have to be carried using Dispatcher.BeginInvoke() and may hang the view if lots of visual items exist.
I'm trying to migrate (mostly mentally at this point) from MS Access to .NET for database programming. I've found one of the first tests to be fairly painful. I'm trying to recreate MS Access's datasheet view in Visual Studio.
Features I use in MS Access Datasheet View that I haven't immediately found in the DataGridView. I'm wondering if anyone can help me out here. I'm assuming that a DataGridView will be used to edit records as opposed to being used as a search/list only.
1) Form Level BeforeUpdate Event - Here I typically run validation code
2) Textbox level BeforeUpdate Event - If I'm feeling anal I'll run validation code here.
3) In MS Access you can sort by multiple columns at once
4) In MS Access columns positioning, sort order, width, row height, etc. are properties
that can be saved in your user's settings (text file or table) and reloaded next time they open the form.
5) In MS Access you can refer to one of the form's recordset fields like this: Me!dteDateTimeEntered = Now() This allows you to edit/enter certain types of data without having to show it to the user.
6) Moving from one row to another automatically saves the changes you made to the record you just exited (assuming you made some changes). It's unclear to me if .NET DataGridView works this same way or if this is something that is determined by the code you use.
7) I often program so that the user can double click in a cell and get a certain action such as dialing a phone number, opening Outlook with an email address inserted, bringing up a windows folder or a picture viewer, or opening a single-record details form. In order to do this I usually grab the primary key of the current record using code like: Me!ContactID or the data from the cell they double clicked in. How can I get this data for the current record in a DataGridView?
8) In MS Access DataSheet view you create textboxes and bind them to specific fields, then you usually name them like txtFirstName. This way you can refer to the value of the textbox using Me.txtFirstName.Value or Me.txtFirstName.Text or you might also choose to refer to the value of the recordset field using Me!FirstName. It appears that .NET's paradigm is totally different so I'm confused. May I create bound textboxes in a DataGridView?
Have you spent some time looking at the documentation for the DataGridView? A quick glance at it seems to answer most of your questions more or less prima facie.
You will have much finer control over many of the items in your wishlist in .net than with VBA. You may also find that the native .net controls are a bit clunky, and prefer to use someone's enhanced control. For data lists in Winforms, for example, I've found Philip Piper's ObjectListView very elegant, extensible and time-saving for handling pretty much everything in your wishlist.
I have a very strange issue and am not sure why it is happening or how to prevent it.
Envionment:
.NET Framework 3.5
WinForm application
C#
VS2008 Pro
Issue:
I have a WinForm containing a TabControl which has a custom usercontrol on two of its TabPage.
The usercontrol i created contains 3 DataGridView controls.
Everytime I go into Desiger of my WinForm, I see that there are SIX (3 * 2) instances of a DataGridView control created.
They are all numbered such as dataGridView13, dataGridView14, etc...
Along each of those DataGridView instances, the associated DataGridViewTextBoxColumn and DataGridViewCellStyle instances are also created.
Pretty soon I had nearly 600 DataGridView instances in the MyWinForm.Designer.cs file!!
Why is this happening and more importantly how to prevent it???
Anyone has seen something like this before??
The designer in Visual Studio has problems handling inherited controls, especially so with the DataGridView control. If it is also a container for child controls, like columns, a new set of children will be generated every time you save a modification.
The only way I have found to address the problem is to make your modifications, save them, then remove the previous list of duplicated controls. The designer at least has the courtesy to number them sequentially by type of control.
Oh, and save yourself the frustration of renaming any of the controls. When the designer generates the new set, it reverts to its default naming practices.
Sorry I don't have better news for you.
I am just trying to wrap my head around MEF.
And as I am really going to love it ( I guess ) I started my first sample project and immediatly stumbled into a big problem and now I am asking myself if I can use MEF for my scenario at all and that is the following:
Imagine that one got some kind of dashboard with, let's say, five regions and above each region there are two comboboxes. The values in the first combobox represent different possible views (for example, chartControl, tableControl, pictureControl, ...) and the values of the second combobox represents the different data sources for the currently selected control.
As the controls are very big in size one wants to download them as needed.
If the user selects one comboboxitem the corresponding control xap should be loaded and displayed in this specific region. If the user selectes another control in the same combobox the control should be removed from the visualtree and the next control should be downloaded and displayed. If the user changes the selection in a different combobox the corresponding control should be loaded again only in this specific region, with perhaps different data.
And to make it a little more interesting - as this is some kind of dashboard one can change the layout from five regions to - for example - ten regions.
I've seen the video "MVVM with MEF in Silverlight Video Tutorial Part 2: Plugins and Metadata" ( http://csharperimage.jeremylikness.com/2010/03/mvvm-with-mef-in-silverlight-video_09.html ) but he is using an ItemsControl and is working with Visibility and he only got ONE region. So I think that this technique is not working for me...
Puh, I hope I could make myself clear!
Thanks a lot for any piece of information!!!
Greetings,
Tim.
Glenn Block has a series about using MEF to write a Silverlight Dashboard: http://codebetter.com/blogs/glenn.block/archive/2009/11/30/building-the-hello-mef-dashboard-in-silverlight-4-part-i.aspx
My company's product is, at its core, a framework for developing metadata-driven UIs. I don't know how to characterize it less succinctly than that, and hope I won't need to for purposes of this question, but we'll see.
I've been trying to come up to speed on WPF, and have been building UI prototypes here and there, and recently I decided to see if I could use Expression Blend to help with the design of these UIs. And I'm pretty mystified at this point.
It appears to me as though Expresssion Blend is designed with the expectation that you already know all of the objects that are going to be present in the UI at design time. But our program generates these object dynamically at runtime.
For instance, a data row might be presented in a horizontal StackPanel containing alternating TextBlocks (for captions) and TextBoxes (for data fields). The number of these objects depends on metadata about the number of columns in the data row. I can, pretty readily, write code that runs through a metadata record and populates a StackPanel dynamically, setting up the binding of all of the controls to properties in either the data or metadata. (A TextBox's Width might be bound to metadata, while its Text is bound to data.)
But I can't even begin to figure out how to do something like this in Expression Blend. I can manually create all these controls, so that I have a set of controls that I can apply styles to and work out the visual design of the app, but it's really a pain to do this.
I can write code that goes through my data model and emits XAML for all these controls, I suppose, and then copy and paste it. But I'm going to feel really stupid if it turns out there a way to do this sort of thing in Expression Blend and I've dropped back and punted because I'm too dim to figure out the right way to think of it.
Is this enough information for someone to try formulating an answer?
I think expression blend is a very good choice ESPECIALLY if you want to design dynamic, datadriven UIs. You can use Blend to desgin DataTemplates that define how a single dataobject is to be presented to the screen. For example, if you have an object of type Person you can define the controls like textboxes, border etc. that then are to be generated automatically for each Person in your list.
You can then fill your ItemsControls (DataGrid, ListView, TreeView ...) with those dynamic databojects and WPF knows how to render them. If a Persopn is removed form the list, the generated visual item will be removed too. This is just a simple example the whole notion of dynamic data is deeply baked into WPF and you can access these features using blend.
To be able to design the datatemplates in expression blend you need to provide sample designtime data.
Also to be effective with all this it is of high advantage if you stick with the MVVM design.