Avalonia: SizeToContent not sizing correctly

Created on 26 Apr 2019  路  13Comments  路  Source: AvaloniaUI/Avalonia

I have made a message box for one of my programs but it is not sizing as it should

image

I have got SizeToContent="WidthAndHeight" in the xaml file

Happens on Windows and Linux (Can't test macOS because I don't have a mac/macOS VM)

repo with code: https://github.com/AzyIsCool/HATE

bug

All 13 comments

This could be a bug with the current Grid implementation. Pls try to refactor your view in a way it doesn't use a Grid anymore. Your other issue with text wrapping could be also related to this.

I'll give it a shot and update on if that fixes my problem (but at the end of the day if that is the case then it would be helpful to be fixed for other people who use grids a lot because they are very helpful in some cases)

Ok so while it fixed the sizing issue when using a StackPanel it did not fix https://github.com/AvaloniaUI/Avalonia/issues/2472#issue-437702629, not going to close this because these two issues seem to be tied together as of now

We know that the Grid has issues and plan to adopt the Wpf implementation when the source code is made available. I guess the StackPanel tells the TextBlock there is infinite space so you have to use a DockPanel instead.

Ping~ I want to have TextWrap in Grid too

Have you tested this with the current nightly builds?

Can't test because current nightly build automatically exits the application before displaying any windows

Why is that the case? Sounds like a bug. How does your AppBuilder look like?


  /// <summary>
  /// Interaction logic for App.xaml
  /// </summary>
  public partial class App : Application {
    public override void Initialize() {
      AvaloniaXamlLoader.Load(this);
    }
    public override void OnFrameworkInitializationCompleted() {
      switch (ApplicationLifetime) {
        case IClassicDesktopStyleApplicationLifetime desktop:
          desktop.MainWindow = new Editor();
          new Editor2().Show();
          break;
        case ISingleViewApplicationLifetime _:
          throw new Exception("Single view not supported");
      }
      base.OnFrameworkInitializationCompleted();
    }

    // This method is needed for IDE previewer infrastructure
    public static AppBuilder BuildAvaloniaApp() =>
      AppBuilder.Configure<App>().UsePlatformDetect();

    // The entry point. Things aren't ready yet, so at this point
    // you shouldn't use any Avalonia types or anything that expects
    // a SynchronizationContext to be ready
    public static int Main(string[] args) =>
      BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
  // (More global properties...)
  }

Full project: https://github.com/verybadcat/CSharpMath/tree/c59ce64fa7c54e610f8dee59f247cd96432d5671/CSharpMath.Utils.NuGet

Environment:
=== Visual Studio Community 2019 for Mac ===

Version 8.4.8 (build 2)
Installation UUID: ce820748-8522-4c64-a791-e9c585bf1f97
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.25 (issue-7441-d16-3-vsmac / 881172e73)

Package version: 606000166

=== Mono Framework MDK ===

Runtime:
Mono 6.6.0.166 (2019-08/d9001b5ae70) (64-bit)
Package version: 606000166

=== Roslyn (Language Service) ===

3.4.0-beta4-19562-05+ff930dec4565e2bc424ad3bf3e22ecb20542c87d

=== NuGet ===

Version: 5.3.0.6192

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.102/Sdks
SDK Versions:
3.1.102
3.1.101
3.0.100
2.2.300
2.2.107
2.1.505
2.1.504
2.1.403
2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.6.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.1.2
3.1.1
3.0.0
2.2.5
2.1.15
2.1.13
2.1.9
2.1.8
2.1.5
2.0.0

=== Xamarin.Profiler ===

Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 11.3.1 (15715)
Build 11C504

=== Xamarin.Mac ===

Version: 6.10.0.21 (Visual Studio Community)
Hash: 02c4b3bdc
Branch: xcode11.3
Build date: 2020-02-18 14:13:31-0500

=== Xamarin.Android ===

Version: 10.1.3.7 (Visual Studio Community)
Commit: xamarin-android/d16-4/d66aed0
Android SDK: /Users/innotech/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
6.0 (API level 23)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.1
SDK Build Tools Version: 29.0.1

Build Information:
Mono: fd9f379
Java.Interop: xamarin/java.interop/d16-4@c4e569f
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.28.0@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/innotech/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.4.0.10
Hash: 2c49a7d
Branch: remotes/origin/d16-4
Build date: 2020-02-20 19:25:52 UTC

=== Android Device Manager ===

Version: 16.4.0.32
Hash: 7a5cb8b
Branch: remotes/origin/d16-4
Build date: 2020-02-20 19:26:14 UTC

=== Xamarin Designer ===

Version: 16.4.0.479
Hash: 074544417
Branch: remotes/origin/d16-4
Build date: 2020-01-22 22:50:22 UTC

=== Xamarin.iOS ===

Version: 13.10.0.21 (Visual Studio Community)
Hash: 02c4b3bdc
Branch: xcode11.3
Build date: 2020-02-18 14:13:32-0500

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 804080002
Git revision: 4f35aa7e44fb398379e512d0bfd6f8df8d34b5ac
Build date: 2020-02-27 16:16:52+00
Build branch: release-8.4
Xamarin extensions: 4f35aa7e44fb398379e512d0bfd6f8df8d34b5ac

=== Operating System ===

Mac OS X 10.15.3
Darwin 19.3.0 Darwin Kernel Version 19.3.0
Thu Jan 9 20:58:23 PST 2020
root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64

Avalonia.Desktop 0.9.4:
image
Avalonia.Desktop 0.9.999-cibuild0006362-beta:
image

Will have a look shortly

@Gillibald Took a look yet?

Not yet. Will have some time tomorrow.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GitHubington picture GitHubington  路  3Comments

Suriman picture Suriman  路  3Comments

grokys picture grokys  路  4Comments

x2bool picture x2bool  路  4Comments

SeleDreams picture SeleDreams  路  4Comments