Good morning. I am looking to get some help on an error I am getting when building a WPF window. I am pretty new to this, so I am confused on how to resolve this.
Here is what I am using to create the project.
Visual Studios 2022 Community Edition
PowerShell Tools for Visual Studios 2022
Here is part of my XAML where the error occurs.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="1000">
<!-- Breaking window in to 2 rows -->
<Grid>
<!-- Main window border -->
<Border x:Name="mainborder"
BorderBrush="Black"
BorderThickness="1"
Margin="2"
CornerRadius="3"
Background="#eeeeee">
<!-- Create header and working rows-->
<Grid>
<Grid.RowDefinitions>
<!-- Header row -->
<RowDefinition Height="50"/>
<!-- Working row -->
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
</Grid>
</Border>
<Grid>
</Window>
I am getting the following error after adding the RowDefinition heights
Error XDG0028 - The TypeConverter for “GridLength” does not support converting from a string
I am assuming that I will need to reference System.ComponentModel.TypeConverter, but does not fix Invalid Markup I am getting for the Window preview.
Hi @themattbamba, I’ve been trying to recreate this issue but not able to. I’m also on VS2022. Your code works fine for me except for the CornerRadius which I had to remove (TypeFace issue on my end, apparently).
Are you able to get the tutorial app working? It’s not clear whether or not you are able to make any apps at all. Would you consider posting the entire project maybe?
Are you launching the .xaml.ps1 file from VS2022 when you press F5 to test?
Is it somehow possible that the CornerRadius is causing an issue for you too and that removing it would help?
Below is my working XAML which I based from the tutorial on the documentation here.
If there’s no response I’m going to chalk this up to some kind of .net framework issue on the local system. Considering trying to reproduce your issue on a clean machine installation of windows with fresh installs of VS2022 and the Posh extension. This is to make sure there is not some old cached data that is not somehow causing a bug in VS2022.
Thanks @DataTraveler! Thank you for getting to this my issue, and I do agree that this is probably a localized issue for me. I will try to see if I can replicate this on another system. Anyways, here are some answers to the questions you asked.
The tutorial app works fine when it is started, but when I changed it to your XAML example the issue happens again.
This works.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<!-- Header row -->
<RowDefinition Height="50"/>
<!-- Working row -->
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Label Content="Label" HorizontalAlignment="Left" Margin="68,38,0,0" VerticalAlignment="Top" Width="197"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="307,41,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
* List item
</Window>
```.
2. I can post the full project, but I pivoted to creating the XAML in a C# WPF project.
3. The app does work when I run the PowerShell script, the issue is with the preview in VS.
4. From what I can tell, VS cannot convert the grid row definition's height froma string to an integer.
Once again, this is probably an issue locally on my machine, but I will add another update after I am able to test it. Thanks again.
Hi @themattbamba, I was able to reproduce the issue. I removed the grid row definitions and added them back in using the UI. Please see the gif. I hope this helps.
I’m having the same issue on Visual Studio 2022 and PowerShell Pro Tools plugin 2022.9.0.
This does not seem environmental as issue appears right after adding Grid with variable side to new WPF Window in PowerShell project.
I was able to workaround it by editing pssproj project file and adding reference to system DLL.
Excerpt from my project file:
Thanks for the follow up on this. I didn’t end up using this method but will test it out. If I have any other questions/issues I will update this thread. Thanks again.