In Xamarin.Forms I want to be able to set the exact height for a control whose height is initially determined using VerticalLayoutOptions only (FillAndExpand in this case) and then, at a later point, reset the height of the control back to be automatically determined.
In normal XAML it is possible to do this via double.Nan but performing the following causes an exception to be thrown.:
control.HeightRequest = double.NaN
How do you set the HeightRequest back to be self-determined?
After some investigation it seems rather than using double.NaN Xamarin.Forms uses the value "-1". Using the following sets the control to automatically determine it's own height again:
control.HeightRequest = -1;
Problem solved but hopefully Xamarin will update this so it uses the normal XAML way soon.
Related
I have from the begin a Picturebox and i want to move it over the screen but something like
image.location = new Point(x,y); or image.location.x = value; do not work. I have searching the half web and i can't find anything about that and in the documentation of Microsoft i can't find something. It could be that i am not find the correct words to use it in google
In contrast to Windows Forms where the control were laid out in absolute coordinates globally, for UWP and WPF it really depends on the container where the control is located. If the control is inside a Grid it's layout depends on the row and column where it lies. To control the absolute coordinates, you have to place it inside a Canvas and then set the Canvas.Left and Canvas.Top properties.
<Canvas>
<Image ... />
</Canvas>
Now in code you can do something along the lines of:
image.SetValue( Canvas.LeftProperty, x );
image.SetValue( Canvas.TopProperty, y );
Alternatively you can use TranslateTransform to move the control relatively to its default calculated position.
I have a couple of ListViews on different pages in my UWP application. For some reason, one of them seems to have Padding along the bottom below the last ListViewItem, while the other does not.
Neither of them has bottom Padding specified, so I'm wondering if this could be inherited from a parent control? I searched the entire XAML of the one with Padding, and it is not set anywhere else either. It isn't a huge problem, but I would prefer my controls to be consistent throughout my application, and I think adding the bottom Padding to the ListView without it to make them match seems silly, especially when I am unsure of why the first one has Padding in the first place.
Is there somewhere to determine where properties are set in the hierarchy, similar to the way CSS works?
Here is what they look like:
No padding:
Padding:
I added a Background to the ListView control to verify that there is no Padding there..
So it would seem it would have to come from the ListViewItem itself, but it does not have the Padding property set.
The issue turned out to be that one of the parent controls of the ListView that was displaying correctly (how I wanted it to) had a VerticalAlignment="Top" set, while all the parents of the other ListView were set to VerticalAlignment="Stretch".
I was finally able to get XAML Spy working properly, and it was helpful in previewing the changes while the application was running so that I could determine which element I needed to set the VerticalAlignment on without recompiling over and over again. Thanks to #ChrisW for the recommendation.
I'm sure this issue must have a very straightforward answer but I can't seem to find it. Any help is much appreciated.
Whenever a new item is added to the UI, either at runtime or dynamically once the program is running, it slides into view to reach its position (with inertia). Only when it reaches that point are certain properties applied: like transform properties or opacity values. For example, if a rectangle set to 50% opacity is added when a button is tapped, it will slide onto the screen about 30 points from its actual position at 100% opacity, reach the correct position and then change to the correct 50% opacity.
I would like to be able to turn off this default behavior so the rectangle appears immediately at the correct position with all the properties set.
I've found that I'm asking two separate questions and that both have been answered on this site (links below).
Individual objects can be targeted using the Transitions property under Miscellaneous in Visual Studio 2012.
How to remove EntranceThemeTransition from object or container in Windows 8 Store Apps?
RenderTransform occurs after EntranceThemeTransition on a TextBlock
How can I find the component in a ScrollViewer that handles the RequestBringIntoView event?
It isn't exposed on the two ScrollBar parts (not directly, anyway).
Thanks for any pointers...
UPDATE: Related: Can I get the ScrollContentPresenter part of the ScrollViewer? How?
Thanks --
Bigger picture:
We have a large Canvas contained in a ScrollViewer. At runtime, an arbitrary number of UserControls (I'll call them 'Blobs') are added to the canvas from the db. Their position and content come from the db. A user can 'select' a blob by clicking on it, and its appearance changes to indicate it is selected.
If the user uses a scrollbar to move the selected blob out of view, then clicks on another blob, the Canvas is scrolled so the previously-out-of-view blob is in view again. I assume this is due to some object raising the RequestBringIntoView, and the ScrollViewer is handling it.
Hope this makes sense...
Yet more info:
Added a handler (sb_ValueChanged) to the Scrollviewer's scrollbar ValueChanged event. Here's the stack from the mouse click that precipitates the scrolling:
OurControl.sb_ValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.RangeBase.OnValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.ScrollBar.OnValueChanged() System.Windows.dll!System.Windows.Controls.Primitives.RangeBase.OnValuePropertyChanged()
System.Windows.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications()
System.Windows.dll!System.Windows.DependencyObject.UpdateEffectiveValue()
System.Windows.dll!System.Windows.DependencyObject.SetValueInternal()
System.Windows.dll!System.Windows.DependencyObject.SetValue()
System.Windows.dll!System.Windows.Controls.ScrollViewer.InvalidateScrollInfo() System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.VerifyScrollData()
System.Windows.dll!System.Windows.Controls.ScrollContentPresenter.ArrangeOverride()
System.Windows.dll!System.Windows.FrameworkElement.ArrangeOverride()
If only I could find out what the FrameworkElement that starts the mischief actually is...
Sorry... it doesn't seems to exist like it does in WPF. Check this link for a handy solution.
Update: Ok... for this you might need to walk the visual tree and some sort of recursive search need to be done. However, assuming you are using the default template for the scrollviewer as seen here, you can directly ask for the ScrollContentPresenter with something like this:
var BorderChild = VisualTreeHelper.GetChild(MyScrollViewer, 0);
var GridChild = VisualTreeHelper.GetChild(BorderChild, 0);
var ScrollContentPresenterChild = VisualTreeHelper.GetChild(GridChild, 0);
I have the following XAML declared:
<controls:PivotItem Header="map">
<my:Map x:Name="map"
CredentialsProvider="Hidden"
Mode="Road"
Center="{Binding AppState.MapCenter}"
ZoomLevel="15">
<my:Pushpin Location="{Binding AppState.MapCenter}" />
</my:Map>
</controls:PivotItem>
The binding works fine - except that the map does not stay centered (initially it centers correctly using the binding on the Center property). The application allows the user to move through a series of records with differing GeoCoordinates. As this happens the bound Pushpin moves appropriately, however eventually it moves off the map because the map does not re-center itself. How can I get the map to re-center itself using data-binding?
I found a second and better resolution that enables databinding. I set the binding mode for the Center to TwoWay:
Center="{Binding MapCenter, Mode=TwoWay}"
This meant I could not bind directly to the GeoCoordinate value on the record that I was mapping (because I did not want that value to be updated if I moved the map center by panning). Instead I had to have a separate property in my view model to bind to which I kept updated with the required GeoCoordinate value from the selected record as the user scrolled through data.
It is strange that the Center property required two way binding whereas the pushpin worked fine without two binding.
At this stage the only resolution that I have found is to set the map view in code each time the mapped point changes as follows:
map.SetView(ViewModelLocator.AppStateStatic.MapCenter, 15);
I would have liked it to work with data binding.