Usercontrol, resize inside the grid - wpf

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.

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.

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.

WPF control origin point

After some investigation, I still can't find method to change origin of control.
So, I want just to place one square exactly in center of another square, without margins, so it will be completely independent of first square size.
Theoretically, it can be easily done with HorizontalAlignment and VerticalAlignment set to Center, since it automatically sets Margin of control to half of width and height of parent control. But it is not so simple.
Simplest way to describe problem is next picture
As you can see, margin is counted towards upper left corner. Which is what I call origin. The perfect solution is to change it to center of first square, but this is where I need help - how can I do that?
Point of origin applies when using a transform object, and attaching the transform to your control. It won't actually effect the behaviour of the margin or left, top properties. If using a transform to place your object, point of origin is very useful.
The top, left (if using cavas) and margin (if using say grid) help govern the "auto" placement by the parent control, and this in turn governs where point of origin for the control winds up being relative to the parent control. The transform object then offsets RELATIVE to where that point of origin is.
The other useful thing is that transform overrides the auto placement in the parent control, or rather, forces an offset to where the parent wants to put it, which in some cases is useful - i.e., you might have boxes listed in a grid and want them to "shake" left and right when you hover the mouse over them, their alignment stays in order to the grid, but the transform lets you bump them away from their "forced" position.
For example, attach the same transform object to 2 controls, and set their origins separate, then apply an animation to the transform object - both controls will animate off the one animation object (if you wanted to their movement in perfect sync).
Well, it was weird enough. The given behaviour can be seen only when using Image, and Center alignment. Can be solved by either wrapping Image in Grid, which will be using Center alignment, or using Stretch alignment with Image (which is much simplier).
<Grid Width="500" Height="500">
<Image Width="250" Height="250" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</Grid>
If you want to reproduce problem I've described in question, replace Stretch with Center in code above.
Probably oversimplifying here but I would just use a Grid to wrap the two items you mentioned like this example (One stretched to fit and one centered):
<Grid>
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Black" BorderThickness="10" Margin="4"/>
<Button HorizontalAlignment="Center" VerticalAlignment="Center" Padding="10">InnerButton</Button>
</Grid>

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.

Get Width Available for Children in a Scrollviewer

How do I get the width available for the children of a scroll viewer in XAML? Thanks.
There's no direct way of doing this that I know of, since WPF automatically passes the available space in to the child controls' Measure() function so that they size to fit the available space.
Note that, by default, it passes in infinity for the vertical direction, since content can scroll forever vertically. You can change the visibility of the scroll bars in both the vertical and horizontal direction to affect whether infinity is passed vertically, horizontally, or both.
The best way of figuring out how wide the child controls actually have to layout in pure XAML would be to create an empty control - for instance, an empty grid - and then bind to its ActualWidth property:
<ScrollViewer>
<StackPanel>
<Grid x:Name="MeasureGrid"/>
<TextBox Text="{Binding ElementName=MeasureGrid, Path=ActualWidth}"/>
</StackPanel>
</ScrollViewer>
Aside from displaying the width that is actually available to controls, I don't see any other use for this information in XAML, though - all of the other scenarios I can think of can use this information implicitly. Can you give us more information on what you are trying to accomplish?

Resources