Image to not cause a row size change - wpf

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.

Related

Xamarin.FormsCustom Renderer (Checkbox) size

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.

Hide overflowing portions of textblock and image outside a wpf Button

I have a WPF button.The ContentControl inside this Button contains other UI elements like Textblock,Images etc.When i increase the font size of the Textblock or the Image etc,or i change the text inside Textblock,then some portion of the text and image can sometimes be seen overflowing outside the button's(ie parent control) height and width if the text ,fontsize or image size is more than the height and width of this button.I want to hide these overflowing portions of the text and image controls,ie which only the portions of the Textblock and Image which lie outside the button contentcontrol's height and width boundary.How can i do this?
I was able to do it.
I simply placed a the entire ContentControl inside a Label and it was done.
ie earlier it was like this:-
<Button>
<ContentControl>
<TextBlock/>
</ContentControl>
</Button>
Now i made it like this:-
<Button>
<Label>
<ContentControl>
<TextBlock1/>
<TextBock2/>
.
.
.
<Image1/>
<Image2/>
</ContentControl>
</Label>
</Button>

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 do I make a TextBox that can grow wider than its parent?

Is there any way I can make a WPF TextBox dynamically grow beyond the bounds of its parent?
For example, I am allowing a user to type in an XPath string that could be very long (wide), I would like one of two possible things to happen:
The textbox could grow wider when the user types a certain amount of characters.
or
When the user initially clicks on the textbox, it kind of 'pops-out' and is very wide, wider than its container.
Is this possible?
You can set a negative Margin to allow it to grow wider than its parent.
<Grid>
<Grid Margin="50">
<TextBlock Margin="0,0,-50,0" Text="This is a very long text." />
</Grid>
</Grid>
You can try the following:
Put both the ParentControl and the TextBox inside a Canvas.
Locate the TextBox using fixed or dynamic coordinates relative to the ParentControl.
Set the TextBox Z-Index to higher value of the ParentControl.
Relocate and/or expend the TextBox based on TextBox events.

How do I move the text in a silverlight textbox

I make a silverlight TextBox. The Text is vertically centered in the box so that I am required to make the textbox a certain size in order to see the text.
Can I make the text appear at the top of the box so that I am not required to have such large textboxes?
If you want to put the text at the top of the textbox then instead of VerticalAlignment="Center" use VerticalAlignment="Top"
If you feel that the text is not filling the textbox then try using a negative number for the padding property in your xaml e.g. Padding="-3"

Resources