You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Used this as an example for a template we're building in the Windows Community Toolkit and ran into some issues with the sample and code. Figured I'd contribute back to the article here the fixes I had to do.
Fixes:
- Off-by-one logic error for cutting size of box (for instance try '6' as a value, should be 2x3 not 3x3 still) (from my understanding of the scenario)
- Missing `{` in `LimitUnboundedSize` method
- Missing `;` in `ArrangeOverride` method
- Improper definition of a Dependency Property (guidelines are strict here about property and DP names aligning otherwise issues can occur, picked a more standard XAML based Panel name here as well for this scenario.
- Also added changed callback to invalidate layout so that the dependency property change actually updates the layout of the control immediately.
- Provided more context for where the adjustment to the code goes.
@@ -183,20 +182,35 @@ It's typical that the input *finalSize* and the [**Size**](/uwp/api/Windows.Foun
183
182
You could compile and use this panel just as it is now. However, we'll add one more refinement. In the code just shown, the logic puts the extra row or column on the side that's longest in aspect ratio. But for greater control over the shapes of cells, it might be desirable to choose a 4x3 set of cells instead of 3x4 even if the panel's own aspect ratio is "portrait." So we'll add an optional dependency property that the panel consumer can set to control that behavior. Here's the dependency property definition, which is very basic:
get { return (bool)GetValue(UseOppositeRCRatioProperty); }
192
-
set { SetValue(UseOppositeRCRatioProperty, value); }
199
+
if (dependencyObjectisBoxPanelpanel)
200
+
{
201
+
panel.InvalidateMeasure();
202
+
}
193
203
}
194
204
```
195
205
196
-
And here's how using `UseOppositeRCRatio` impacts the measure logic. Really all it's doing is changing how `rowcount` and `colcount` are derived from `maxrc` and the true aspect ratio, and there are corresponding size differences for each cell because of that. When `UseOppositeRCRatio` is **true**, it inverts the value of the true aspect ratio before using it for row and column counts.
206
+
And below is how using `Orientation` impacts the measure logic in `MeasureOverride`. Really all it's doing is changing how `rowcount` and `colcount` are derived from `maxrc` and the true aspect ratio, and there are corresponding size differences for each cell because of that. When `Orientation` is **Vertical** (default), it inverts the value of the true aspect ratio before using it for row and column counts for our "portrait" rectangle layout.
197
207
198
208
```CSharp
199
-
if (UseSquareCells) { aspectratio=1/aspectratio;}
209
+
// Get an aspect ratio from availableSize, decides whether to trim row or column.
0 commit comments