Xamarin.FormsCustom Renderer (Checkbox) size - checkbox

I followed this article ...
https://alexdunn.org/2018/04/10/xamarin-tip-build-your-own-checkbox-in-xamarin-forms/
to add a checkbox control to Xamarin.forms. It works well, but I cannot figure out how to resize it.
Details:
I have a layout with a rowspan=2 cell spanning two regular cell heights. I get a tiny checkbox sitting in the center of the rowspan, with lots of unused space around it, and users find it is hard to hit when tapping. Therefore I want it double its size according to rowspan=2.
Any idea how I can accomplish this?
Edit1: Checkbox XAML
<ctrls:Checkbox
Grid.Row="0"
Grid.Column="2"
Grid.RowSpan="2"
OutlineColor="#AFCB08"
CheckColor="#AFCB08"
HorizontalOptions="End"
VerticalOptions="Center"
WidthRequest="50"
HeightRequest="50"
IsChecked="{Binding Done}"
CheckedCommand="{Binding CheckedCommand}" />
(Including Senthamizh suggestion to try WidthRequest and HeightRequest)
tried several Values for width and height: 10,50,100. Observations: in no case the checkbox would enlarge. When I used "10", the checkbox collapsed into a vertical line. Playing with DEFAULT_SIZE in CheckBoxRenderer.cs never had any notable effect.

Related

Dynamic scrolling in a WPF application with ItemsControl object

In my xaml, I have some object made by me. I put them in row and, if the window is too little for all, I go in a new line.
The problem is when the window is so little that, also in a new line, the elements can't be all shown. The solution is simple: scroll bar!! But, if I set the Vertical/HorizontalScrollBarVisibility to auto, it doesn't go to a newline anymore.
This is my xaml:
<ScrollViewer CanContentScroll="True" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled" >
<ItemsControl Name="ItemGroups" ItemsSource="{Binding NotifyItemUI}" />
</ScrollViewer>
and this is a screenshot what I need as my goal:
For example, if I resize my area vertically, and I have 3 rows of objects, in this way I can't see the third row if the window becames too little. In this case, I'd like to see a vertical scrollbar to scroll it.
Same thing horizontally: if I have too many elements for one single row, I have to scroll it horizontally.
What you describe looks like a WrapPanel, but the way you write about it suggests it is a custom control, so we cannot see what your ItemsControl is doing for layout.
However, ScrollViewer can have tricky interaction with a Panel. If the Panel measures to infinity, it will always consider itself big enough, and never tell the ScrollViewer it is out of room. The result is that the ScrollViewerdoes no know the scrollbar is needed. If this is your problem, then setting the Width and Height properties, or maxima as #Sheridan said, ought to fix it.

Usercontrol, resize inside the grid

I have a typical user control with some drawing on the canvas.I have plugged that user control in a grid with following code
<Routine:FlashUserControl x:Name="FlashControl" Grid.Row="0" Grid.Column="2" Grid.RowSpan="9" Grid.ColumnSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />,
but the user control overflow above the grid region (as specified in the attached image) rather than fitting into the region (2 Coloumns x 9 rows)
Even Though VerticalAlignment, HorizontalAlignment, HorizontalContentAlignment and VerticalContentAlignment defined as stretch in user control, why it is happening?
UPDATE:
If I summarize the issue, my drawing entities inside the usercontrol exceeds the canvas limits, I think I need to re-scale the drawings
There can only be two reasons why a UI element that has been set into a particular section of a Grid might exceed its bounds. The fist reason might be that as mentioned in the comments, the UI element has had its Width and/or Height property values explicitly set to values that are too big for its available area. The fix for this is obviously to not explicitly set these values.
The second reason might simply be that you Grid has not been declared correctly. Perhaps you have the wrong number of rows and/or columns? Again, the fix for this is simple. Please show your Grid so that we can verify this point.

Image to not cause a row size change

I have a simple Grid with three columns. In one of these rows, I have (in column order): A TextBlock, a TextBox, and a Button. The Button contains an Image for it's content.
My issue is that the Image always sizes to display it's full content which enlarges the button. I don't care what size the image's source is; I want the Button to be the same size as the row already is due to the TextBlock and the TextBox. I don't want to specify a hard coded value for the image size. That's not the point. If a user's theme and/or font changes, the Grid row should still work as expected and the Button should always be the correct size.
I've tried a ViewBox, all sorts of alignment properties and bindings. No luck. Any ideas anyone?
<TextBlock VerticalAlignment="Center" Margin="4,0" x:Uid="RONumber" />
<TextBox x:Name="tbRO" InputScope="Number" MaxLength="8" Grid.Column="1" Margin="4" />
<Button x:Name="btnSearch" Click="Search_Click" Grid.Column="2">
<Image Source="Long Source Removed For Readability" />
</Button>
In the image below you can see the TextBox and to the right the Button with the Image inside it. Right below it is another TextBox which is correctly sized. And if I remove the button the top TextBox sizes the same.
Ok, so here's the answer. Because the elements are in the same row the XAML is not working. The binding I had made (before I even posted this question) to the ActualHeight always was 0. I instead bound the MaxHeight of the button to the ActualHeight of a random TextBox on another area of the screen. This worked.

Rotate the text inside a small grid/panel

<Label Grid.Row="1"
Height="70"
Margin="2"
Width="300"
Content="{l:Translate Key={x:Static l:MultistringTags.SHOW_MENU}}"
DockPanel.Dock="Bottom"
FontSize="20"
FontWeight="Bold"
Foreground="White">
<Label.RenderTransform>
<RotateTransform Angle="270" />
</Label.RenderTransform>
</Label>
Here I want to rotate the text, which is inside a grid and a grid column width equals with text height. In this case I see only part of text like if text was drawn without rotating cutted of by grid width, and rotated to required angle. I have tried panels, they give me same result.
Does anybody know some workaround to make it show all the text and I don't want to use image because text should be translatable.
I believe if you change it to set the LayoutTransform instead of RenderTransform, it will prevent the text from being cut off.
<Label.LayoutTransform>
<RotateTransform Angle="270" />
</Label.LayoutTransform>
Further to #nekizalb's answer stating that you should use a LayoutTransform, the reason that you would need to do that instead of using a RenderTransform is because of the timing at which each occurs... a LayoutTransform will affect results of layout.
From the UIElement.RenderTransform Property page on MSDN:
A render transform does not regenerate layout size or render size information. Render transforms are typically intended for animating or applying a temporary effect to an element. For example, the element might zoom when focused or moused over, or might jitter on load to draw the eye to that part of the user interface (UI).
From the FrameworkElement.LayoutTransform Property page on MSDN:
In contrast to RenderTransform, LayoutTransform will affect results of layout.
Example scenarios where LayoutTransform would be useful include: rotating elements such as menu components from horizontal to vertical or vice versa, scaling elements (zooming in) on focus, providing editing behavior, etc.

How to mix text-only RibbonToggleButton and image-only RibbonButton in Ribbon for WPF?

I'm using the Microsoft Ribbon for WPF October 2010 and have got 3 buttons next to each other, inside a RibbonControlGroup. The left and the right ones are text-only RibbonToggleButton controls, the one in the middle is an image-only RibbonButton. The buttons have a defined width to match the row above.
My code:
<r:RibbonControlGroup>
<r:RibbonToggleButton Width="110" Label="Outgoing" IsChecked="True" />
<!-- Padding and Height set to align the buttons/image -->
<r:RibbonButton Width="30" Padding="5 0" Height="24" SmallImageSource="Images\Small\arrow_swap.png" />
<r:RibbonToggleButton Width="110" Label="Incoming" />
</r:RibbonControlGroup>
The problem is that as soon as I apply the SmallImageSource to the middle button, the other two get spacings for images, causing the text not to be centered anymore. That is problem (1).
Because I didn't find a quick solution, I tried to add the image of the middle button not via SmallImageSource, but by adding it as <Image> for the content of the button. However, the button would remain empty. That is problem (2).
My third solution was to add images to the left and the right button, too. Unfortunately there is nearly no margin between the image and text, which looks quite ugly. I tried several things to enlarge the margin like adding a <Style TargetType="Image"> to the <RibbonToggleButton.Resources>, but although the editor accepts it and displays the spacing at designtime, the margin is gone again at runtime. That is problem (3).
Does anybody have an appropiate solution to any of the three problems? I cannot get it to work. The number of the problems is also the preference of the alternatives, (1) being the most favourite to use with an appropiate hack.
It seems you cannot do that. Its by design.
As per MSDN (here about half way down the page):
Related ribbon controls can be grouped together in a RibbonControlGroup. When a control group is resized, one RibbonControlSizeDefinition is applied to all of the controls in the RibbonControlGroup. The RibbonControlGroup is positioned in the RibbonGroup as if it were one control.
All the controls in a RibbonControlGroup shares the same RibbonControlSizeDefinition. Hence, in your case image will be added for all the buttons.
You may use RibbonGroup instead if you do not want to glue all your controls very closely. This way you can customize each button container by using different RibbonControlSizeDefinitions.

Resources