Vertical text in WPF grid
-
I am making a table, using a grid, with one large left column, and to the right, four (or possibly more) check boxes / radio buttons, each in a quite narrow grid column. There is not enough room to label each of the CBs/RBs on every line, so I put the label in the top row, rotated 270 degrees as a vertical text, in a tall (100 units) but narrow (27 units) cell, just enough to hold the longest label. My problem is that WPF appearently clips the label to the edges of the grid cell before rotating the contents, so in my first attempt, the label was clipped at 27 units while it was horizontal, and then this less-that-a-third of the label was rotated to vertical position. I discovered that I could use Grid.ColumnSpan="4" to give the labels enough horizontal space to be drawn in full before rotating. That works only if three extra columns exist, and that holds true only for the first radio button. So I have to place all four of them in column 1 (spanning cols 1-4), and then translate them horizontally to appear visually over their intended columns. This is ugly, messy, inflexible and most certainly not something I would like to maintain in the future, with columns added, widths/heights adjusted, labels changed...:
-
I am making a table, using a grid, with one large left column, and to the right, four (or possibly more) check boxes / radio buttons, each in a quite narrow grid column. There is not enough room to label each of the CBs/RBs on every line, so I put the label in the top row, rotated 270 degrees as a vertical text, in a tall (100 units) but narrow (27 units) cell, just enough to hold the longest label. My problem is that WPF appearently clips the label to the edges of the grid cell before rotating the contents, so in my first attempt, the label was clipped at 27 units while it was horizontal, and then this less-that-a-third of the label was rotated to vertical position. I discovered that I could use Grid.ColumnSpan="4" to give the labels enough horizontal space to be drawn in full before rotating. That works only if three extra columns exist, and that holds true only for the first radio button. So I have to place all four of them in column 1 (spanning cols 1-4), and then translate them horizontally to appear visually over their intended columns. This is ugly, messy, inflexible and most certainly not something I would like to maintain in the future, with columns added, widths/heights adjusted, labels changed...:
There's few good reasons to use a Label over a TextBlock. You could try rotating a StackPanel with Labels.
Slett permanent Hopp over Legg inn i SiKo Kopier til kildedisk
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
I am making a table, using a grid, with one large left column, and to the right, four (or possibly more) check boxes / radio buttons, each in a quite narrow grid column. There is not enough room to label each of the CBs/RBs on every line, so I put the label in the top row, rotated 270 degrees as a vertical text, in a tall (100 units) but narrow (27 units) cell, just enough to hold the longest label. My problem is that WPF appearently clips the label to the edges of the grid cell before rotating the contents, so in my first attempt, the label was clipped at 27 units while it was horizontal, and then this less-that-a-third of the label was rotated to vertical position. I discovered that I could use Grid.ColumnSpan="4" to give the labels enough horizontal space to be drawn in full before rotating. That works only if three extra columns exist, and that holds true only for the first radio button. So I have to place all four of them in column 1 (spanning cols 1-4), and then translate them horizontally to appear visually over their intended columns. This is ugly, messy, inflexible and most certainly not something I would like to maintain in the future, with columns added, widths/heights adjusted, labels changed...:
That markup looks OK to me in Kaxaml[^]. Perhaps you need to use a layout transform instead of a render transform? LayoutTransform vs. RenderTransform - What's the Difference?[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
That markup looks OK to me in Kaxaml[^]. Perhaps you need to use a layout transform instead of a render transform? LayoutTransform vs. RenderTransform - What's the Difference?[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Aaah - thanks a lot! I hadn't leaned the difference between LayoutTransform and RenderTransform. Although LayoutTransform is mentioned in my XAML textbook, it isn't illustrated in an XAML example, so I hadn't grasped the difference between the two concepts. LayoutTransfor gives me code that looks a lot more like I want it, a lot more direct and maintaninable. (I still think XAML often requires an extreme amount of red tape to do fairly simple things. That is an inherent "quality" of XAML, not of transforms in particular, but it certainly is clearly illustrated in transforms!)