I have stumbled upon a minor problem, which leaves me unable to continue my code.
I need to be able to recieve the accumulated height of all children in a grid.
For example: There are 3 children. Each of them has a height of 40, a Top Margin of 5 and a Bot Margin of 5. Which means their height is actually 50x3 = 150 together.
How can I check that height?
I need it for a part of the code:
_contentGrid.Height = ??? -> Height of all Children together
Why I want that does not matter. Better options do not matter either. I need to recieve this height somehow.
Thank you for your time.
Narakuvera
If they all have the same Height you should look at the ActualHeight-Property:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.actualheight%28v=vs.110%29.aspx
_contentGrid.Height = (ActualHeight+10)*3;
Related
here is my problem:
I want to have a bunch of Text-GameObjects to be evenly distributed across the screen horizontally.
So I took a Layout-Group and added it onto a Panel, which is streched across the screen, with the following settings:
Panel Settings
(The Layout Element on the Panel is not important here, I think, but the Panel itself is controlled by another Object to stretch across the Screen)
Now, I add the Text-GameObjects via Script. That looks like that:
days[i].transform.SetParent(GameObject.Find("Day Panel").transform);
days[i].AddComponent<Text>();
days[i].transform.GetComponent<Text>().font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
days[i].transform.GetComponent<Text>().fontSize = 25;
days[i].transform.GetComponent<Text>().color = Color.black;
days[i].transform.GetComponent<Text>().alignment = TextAnchor.UpperCenter;
days[i].transform.GetComponent<Text>().text = shownDates[i].Day.ToString();
days[i].transform.localScale = new Vector3(1, 1, 1);
days[i].transform.localPosition = new Vector3(0, 0, 0);
Now I have the problem, that the width of the text-GameObjects is influenced by the length of the string I show with them. So if a text-GameObject has a 3-char-long string in it, it is wider than a text-GameObject next to it with a one-char-long string. But I need to distribute the width "fairly" between the Text-Objects, independently from what's inside.
I hope, that you can help me, Thanks :D
Making my comment an answer as it answers your question. You have two options to solve your issue.
The first I provided is not as robust and not modular that will work if you know the number of child objects at compile time. You can utilize the field minWidth of a LayoutElement. By setting this value as the width each element needs to be to evenly fill the space, the text object will be no smaller than the value you give it. However, if you ever add any new objects to your layout group at runtime or at any other time, you would need to recalculate these values so it is not a great solution.
The second solution which would allow for almost no work by you is to add an empty parent RectTransform to fill the space above the text object. With the layout group forcing the width and height to expand to the container, each RectTransform will fill the space evenly, while the childed text can be whatever size it needs to be. Here is the hierarchy setup of this solution:
And here is the solution working:
In the example, the parent objects are panels with Image components. I only did this to show that there is a divide between each object like you want. You can remove this component and still have the object retain its structure.
I want to create a plot that dynamically displays active elements as rectangles. I have achieved a first version that is actually ok using OxyPlot.Annotations.RectangleAnnotation which I add to myPlotModel.Annotations, you can see it in the image hereafter:
Example of wanted display
The thing is that after a while, the amount of drawn rectangles make the update not smooth as I update the shown timewindow (which is set to 15 seconds). I have already set a maximum of drawn elements that suffice to cover the displayed window (i.e. the rectangles get removed as they are too far in the past), but the rendering is still jerky. I draw the rectangles by allocating them to an equal fraction of the Y-axis, that is the third one from the top gets:
rowNumber= 3.0
minimumY = maximalY - maximalY / totalElements * rowNumber
maximumY = maximalY - maximalY / totalElements * (rowNumber + 1.0)
And the Y-axis is hidden.
My question:
Is there a smarter way of creating such a display that would be less computationally heavy, and therefore allow a smoother update? I do not have to stick to OxyPlot, it is simply the easiest way that I found to obtain what I wanted.
Thanks for your answers!
Technically, the answer to your question is "Yes".
There are a number of ways to do this.
You could have a vertical itemscontrol that had an itemscontrol in it's template. That could have a canvas as it's itemspresenter and you could bind canvas.top and canvas.left to properties in it's content. Template each into a rectangle and bind height and width.
And of course do something about the scale on the bottom and the column of activity labels or whatever you want to call them there.
Unless you're using an absolutely ancient machine, that'd just fly.
It's quite a lot of work but it would probably be quicker to write that than to search through a load of alternative packages and decide which was optimal.
I am using the Microsoft Chart Control.
I am trying to adjust the height of the chart area programmatically. Depending on the rows. Because the Microsoft Chart control requires a height, which cannot be in percentages, nor Auto. Depending on the selected query, the chart can have 1 bar or it can have 100's. This is why I need to adjust the height because bigger data sets appear squished and not readable.
What I have tried is adding a counter heightCounter which is the number of bars on the chart.
int newHeight = (heightCounter * 10);
// Maximum height aloud on Chart Control
if (newHeight > 32767)
newHeight = 32767;
Chart1.Height = newHeight;
This sometimes works O.K. with smaller data sets
but when I have very large datasets the title looks very spaced out because the height is too large.
Is there a proper way to achieve this?
I think that the way you are approaching the problem is along the right lines, taking a count of the number of series' in the datasource in order to obtain a proportional height.
However, I would be inclined to declare the width of each bar as described here. This would give you more control than using a static multiplier such as the 10 you have.
I would also be inclined to set the height permanently as the calculated height, unless of course the minimum height is a desired feature.
Also, as a side note, isnt increasing by 10 for each quite significant? Have you tried halving that? If I remember rightly, the width of the bars will autmatically scale themselves (if not specifically declared by you).
I've stumpled upon a problem that I can't solve. I am given the amount of elements to populate a grid with, but through this, I need to know (beforehand) what the width and height (in amount of elements) the grid should be.
I would like the aspect ratio between width and height of the grid to be 1:1. Even with this simple aspect ratio, I fail at doing the calculations.
Could someone help me?
Example provided below
Let's say I have 9 elements in total. The width and height of the grid would then be 3. This is easy (by using the square root of the amount of elements).
But what about (for instance) 10 elements, or 11? With 10 elements, I would like either the width or height of the grid to be 4. Same with 11.
How do I perform these calculations?
It all depends on how you want to handle non-square layouts. Either way, though, you can take the square root of the number of items, and then take either the floor or ceiling to get the desired width/height.
For example, Math.Sqrt(11) is ~3.3166, so Math.Ceiling(Math.Sqrt(11)) == 4, which is your desired height/width.
I have a number of panels in a single window in C# application and I created 2 scrollbars, one for horizontal and one vertical. This is what I currently have:
picture with 2 scroolbars http://www.simnet.is/elinnils52/scrollbar.jpg
I have 1 variable and that is the total height all the items take & need.
Here is my code on scroll change:
for (int i = 0; i < this._splitMainView.Panel2.Controls.Count; i++)
{
this._splitMainView.Panel2.Controls[i].Location = new Point(
3 - _scrollBarX.Value,
3 + (132 + 6) * (i - 2) - _scrollBarY.Value);
this._splitMainView.Panel2.Controls[i].Refresh();
}
The scrollbar maximum is the total amount of all the containers height, the space in between and a few pixels extra.
As you can see from the picture, it doesn't look good. Even if the maximum in this case is a little around 50 - 100 pixels it still looks like it's a thousand pages long. When I change the SmallChange and LargeChange, the scrollbar bar itself lengthens but then it wont reach the maximum pixels. It will be able to get almost at the end (depening on the SmallChange and LargeChange value) and leave around 5 - 29 px left. And as everyone knows, seeing half is not good.
Does anyone know how to overcome this obstacle or a better way to implement it?
Why not just make the maximum value of the scrollbar the overflow (visible area height - panel height)? Then just set the top of the panel to the value of the scrollbar * -1.
Is there a reason not to use the AutoScroll property?