Anyone have any suggestions on how to insert a row or column in a WPF Grid using (preferably) Visual Studio 2008?
It's no problem to add a new RowDefinition or ColumnDefinition, but I'm really not too excited about the prospect of incrementing the Grid.Row or Grid.Column for the large number of cells that are affected by the insertion. Has anyone come up with a clever way to automate this (perhaps with a regular expression find/replace operation)?
If this can't be done in Studio, can it be done in Blend?
Use smaller size grids in your applications and then put those grids inside other grids, or try some of the WPF grid tools by Karl on WPF
VS2010 looks like it will have a better editor.
Blend is fairly good at inserting rows - when in design edit mode you can click the edge to add a row; Blend will then adjust your layout to look the same with the edited row. You will still need to manually move elements around the grid, but it should be less work overall.
I had the same problem, and used vim to increment the row numbers. This was my expression:
:.,$s/\(Grid.Row="\)\(\d\+\)/\=join([submatch(1),submatch(2)+1],'')/
Explanation:
:.,$s substitute (:s) from the current line (.) until the end of the file ($)
/\(Grid.Row="\)\(\d\+\)/ searches for Grid.Row=" followed by a 1 or more digit number (\d\+). Both parts are between \( and \) to use the submatch function.
\=join([... ],'') joins the strings in the array between [ and ].
submatch(1), the first submatch, ie the text Grid.Row="/
submatch(2)+1, the second submatch, ie the number incremented with 1.
Related
The main method I have for altering the formatting of the final reports is in SQL Server Report Builder.
I have a table within this system which currently is as shown below with some information blacked out.
As shown currently the second line (as shown by 004A) of groupings (referred to as a subsample) comes up with blank areas in the second, third, and fifth columns where the cells have been hidden.
This shading has been done with the following code:
=Iif(Left(Fields!LabSampleNo.Value,3) MOD 2 = 0, "WhiteSmoke", "Transparent")
Is there a way to fix this issue without having to go to coding outside the report builder or by making the fields no longer hidden?
Any help would be great.
As the textboxes are hidden you will not be able to see the backcolor. It is the entire textbox you are hiding, not just it's content.
So the answer to your question is no, you will have to make the textboxes visible again however you can just wrap your value expression inside the same logic as you used to hide the columns.
So, let's say you are hiding the columns based on the first column have non numeric characters and the column you wanted to hide was called myDataColumn then you could do something like...
=IIF(ISNUMERIC(Fields!myFirstColumn.Value), Fields!myDataColumn.Value, "")
Your row's background color expression would remain the same.
Assume we have a DataGrid like this :
First column is constant. others are come from database. In columns we display name of football players for example and below them we display some statistics about them .
What control do you suggest to use ?
If you suggest DataGrid how do I create columns and rows and connect them to data source ?
Any code example would be appreciated.
The functionality you are looking for is typically called a pivot table or Matrix. See Dynamic data matrix WPF for an example of how to do so in WPF.
Edit: If you are not trying to pivot, but just rotate it 90 degrees, there is a rather good answer on how to do that, too: WPF horizontal DataGrid. Basically just use a couple of LayoutTransforms to rotate the whole thing, then another set to rotate the cells back to normal.
I need to insert into a border text with bullets (look at the next picture for example):
Is there any special property for this or should I use some container like grid and get this manually?
If your solution rely on Expression Blend it fine by me (I`m using Blend 4).
Thanks
Ofir
I'm a developer who's trying to get the hang of Blend. I've always used Blend to mess with control templates and such, but I'm trying to get the hang of using it for basic UI design, since I figure it's probably a bit faster than typing the XAML up manually in Visual Studio.
Right now I'm just trying to create a basic Grid, but I'm seeing two default behaviors that I'm hoping someone can show me how to change.
1) When I hover my mouse outside of the design surface, I see the temporary yellow line to show up, where the new Grid Column / Row will be when I click. The problem is that the newly created rows are set to heights like 0.2297* How do I get Blend to attach regular heights, like 250?
2) Ignoring 1), once I have some rows and columns, when I drag a button, or combo box, etc, onto one of the cells, it drops it exactly where I release the mouse, while adding some large margins to position it there. Is it possible to tell blend to just drop the control into the cell, and leave the margins alone?
Grids are awesome but it takes a bit of play to get proficient at working with them in Blend. Here are some tips to get you started (I cover this in detail in chapter 4 of my book).
1) When you use the snap lines to create rows and columns Blend automatically makes them relative (Star) sized, which is the behavior you are seeing. To change the row/column style to fixed (Pixel) sizes, click on the Padlock icons to the left and top of the desired rows and columns. Then, either edit the values in XAML or you can click near (but not on) the padlock to select the row or column. This will open the sizing properties in the Properties panel.
2) The short answer is "No". Blend will always add Margins when you draw the element in a cell unless you take care to draw them to the borders. This is too difficult and time consuming, so I just make sure I draw it somewhere inside my target cell. Now I can right-click the element and select "Auto Size > Fill" and the element will fill up the cell: no Margins, Width and Height set to Auto, and Horizontal and Vertical Alignments set to Stretch. [FWIW, addressing this is my number one feature request for Blend.]
I hope this helps.
To answer point 1) Blend is creating proportional grids so that the columns remain the same relative widths when you grow or shrink the grid rather than absolute grids. So if you want absolute grid widths you'll have to go in and edit the values by hand.
I find that it's easier to create the basic form in Blend and then tweak the values in the text editor - either in Visual Studio or Blend itself.
As for point 2) I've just tried this and as long as I click inside the column/row on the grid when placing a button it adds it to the correct column/row of the grid as expected. Select the button and then just double click inside the grid - this should add a button of default size where you clicked, but in the grid. (It would be much easier if I could see what you were doing).
Ok I have the following problem in Silverlight. I have a control with 2 columns. On the left is a stack panel with line numbers and on the right is a textBox.
So when I write in textBox without wrapping turned on I can simply create the right count of numbers on the left, because I'm searching for '\r' in text.
But when I turn on wrapping I have no control over the count of lines in textBox.
Is there a way to get to that count? Or a way to know which line in textBox is going to wrap?
I hope you can understand what I'm trying to do.
There's one way to do this. You can simulate the word wrap operation in the background using a TextBlock. Here is a good link of the complete solution to this problem.
Extended TextBox control with MaxLines property
Is it not possible to create your items in code before they are passed to the view. This would enable you to bind a list of items to a listview and style them as you wish.
You need to user a value converter to count the number of char / lines and then trim that number if you wish to. Unless you use fixed width, you can't really count or calculte in advancet the size, since each application might be displayed differently (due to different sizing option).
There are two great sample chapters on Windows Phone and Silverlight for Windows Phone on the LearningWindosPhone.com site. There is great Windows Phone Trainng material , and dont forget the Windows Phone Develoeprs Blog
Yes there is a way to get the number of lines occupied by the text in the textbox. It's not that simple though 'coz you have to simulate the behavior of the word wrap in order to count/predict the number of lines generated as a result of a word wrap. I have the solution described here in detail.