How to hide the particular row of already existing grid programatically - c#

I had created a grid(silverlight5) by doing this Grid bigGrid = new Grid(); using silverlight.
Then i assign it 3 columns and 7 rows in it.
Now each cell has a textblock. And it works fine.
I have to create opacity on any particular row of this already existing grid (bigGrid).And this particular row will be decided dynamically.
How to achieve this in c# code ?
I mean i need something like :
bigGrid.row[particularRow].Opacity=true; (could someone please correct me ?)

I can think of two ways to achieve this.
First, you can't simply set a row(RowDefinition)'s Opacity, because RowDefinition is not a UIElement. What you can do is that you set the Opacity all the elements on this row to 0. In your case the elements would be 3 TextBlocks.
Also you can create a Rectangle on top of the entire row (RowSpan of 3) and set its Fill color to match your Grid's color as well as its Opacity to 0. When you want to hide this row, simply set the Rectangle's Opacity to 1 to block the visual of the TextBlocks.

Related

anchor not sizing buttons properly and text disappearing how to fix it?

in the video below you can see how my buttons behave when i try to resize the window after anchoring them. My application does not have an exist button for some reason either, could not find a solution online and have no clue on how to fix it for the time being. Sorry for potato quality....
https://youtu.be/6WY_19Qdy4c
Did you know that sometimes anchor cannot fix of what will you want to achieve?
Instead of anchoring you can use tableLayoutPanel?
The only properties of tableLayoutPanel is Dock = Fill;
After that you can now add columns and rows in the table and button inside the cell, it will automatically resize your button.
Add a tableLayoutPanel set Dock to Fill
Click tableLayoutPanel
Edit Rows and Columns (Add Column or Rows Change Absolute to Percent it should be 50%)
Press OK
If you want to span Rows and Columns click the control inside the Cell and find ColumnSpan and RowSpan in the properties

Do not see a label resize in tablelayoutpanel

I have a tablelayoutpanel and I have 5 labels on the first row (there are 4 rows). there are 5 columns and the width of the last column is the width of the scroll bar (basic scrollbar). When I put commands on the panel, the scrollbar is sometimes visible, sometimes not, and I resize my last column according to that. My problem is when I do not have the scroll bar and just after I have it: I want to resize my labels but without seeing the change happen.
I tried Suspend and Resume, but it doesn't work correctly. I tried also to set visible or not the tablelayoutpanel but nothing.
here the code :
tableLayoutPanelGroupView.ColumnStyles[5].Width = 0;
and after :
tableLayoutPanelGroupView.ColumnStyles[5].Width = SystemInformation.VerticalScrollBarWidth;
Finally, I found a solution: before changing the size of my last column in the tablelayoutpanel, I set visibility of my labels to false and I reset visibility to true when I'm done.
Thanks to persons who try to help me!

C# WPF - Automatically put Images in rows

Let's say I've a grid and some images which I want to show. What I want to do now is putting the images in a straight row. If they don't fit inside the grids width anymore, they shall be put in the next row. I feel like there has to be a way to do that automatically, like the LayoutManager in Java for example. Any ideas?
You should use wrap- or a stackpanel inside your cell and set some alignments (for example set verticalAlignment to "strech").
http://www.wpf-tutorial.com/panels/introduction-to-wpf-panels/

WPF DataGrid changing the cell background color for unused areas

I am heavily customizing the visual appearance of a WPF DataGrid using code behind. The user can configure the background. I have no issue setting the cell background for the cells in a data column to a different color. However I need to also change the cell background color for the undefined area at the end of each row.
For example, I have a row with 6 columns of data. There is more width to the row than what all of the columns take up, leaving an unused area on the right of the row. I cannot seem to be able to programmatically in code behind change the background color of this unused area. I want to set it to be the same as what I used in the rest of the grid.
Anyone have any ideas? Please only provie code behind solutions, not XAML solutions.
If you are doing this for a selected item try this:
var row = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromItem(dataGrid1.SelectedItem);
row.Background = Brushes.<chosen color>;
Other than that you should just be able to set the RowBackground color.
dataGrid1.RowBackground = Brushes.<chosen color>;

WPF: Grid layout - how can I get row and column of element with MouseMove or similar events, when cursor is over empty cell?

As I stated in title to this question - I have an WPF Grid based layout with two header rows and few empty ones. Grid has about 100 columns.
I am trying to achieve the situation, in which I will be able to highlight the cell of empty row, when mouse is over it (and fire an event, when user will click this cell).
I sketched my concept:
When the cursor is over the cell in the second row and third column, I would like to change the border of this cell and knowing the row and column number - change to borders of few other cells.
Thanks for any help.
What you'd usually do in such situation is to add a dummy UIElement,e.g. a Border, Rectangle (or a ContentControl that later could hold your actual content) that fills the cell completely and then on MouseMove query Grid.GetColumn Grid.GetRow on the hit UIElement. You can then loop through all children of your grid and change the borders where needed.
But if I look at your sample picture it seems that you want display a helper lines hinting row and column of your current cell. This can be easily done using Adorners. It is basically an additional layer on top of everything where you can place additional visuals that are bound to size and position of the coneceted control. You woould create an Adorner for the current cell (Border, ContentControl)

Categories

Resources