-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When converting a WPF form, the Handles command in the code behind file is skipped. #1141
Comments
I checked around and none of the VB->C# converters are doing this. They all just leave it for you to do manually. Manually does not work for me with a million+ lines of code. I just asked ChatGPT to please do this for me and it did. So, workaround is working. |
Thanks for the report. There is a whole bunch of code in the converter about dealing with Handles clauses in various different situations. While it'll be hard to perfect the code and I don't have time to take it on right now, you may find that running the converter in debug mode looking at the state around here allows you to tweak things to work for you situation and inform a fuller bugfix: |
I will add one more possible solution... not promising I'll have time to dive into the code. If I begin with:
The XAML doesn't get changed, and the code-behind converts to:
From my memory ... the VB above used to be the default generated code in some older version of Visual Studio - it would add "handles" rather than dealing with it in XAML. What VB does today is the same as what C# does:
From what I'm seeing so far, this is causing most (all?) of my conversion failures with the "handles" code. |
Thanks for the extra info. If you do end up diving into the code, just ping any questions on here and I'll do my best to assist |
This is a pretty obvious solution for WPF, but it does not work for winforms.
My legacy vb apps use winforms.
Thank you
From: nick2893 ***@***.***>
Sent: Tuesday, February 25, 2025 9:02 PM
To: icsharpcode/CodeConverter ***@***.***>
Cc: Mark Johansson ***@***.***>; Author ***@***.***>
Subject: Re: [icsharpcode/CodeConverter] When converting a WPF form, the Handles command in the code behind file is skipped. (Issue #1141)
I will add one more possible solution... not promising I'll have time to dive into the code. If I begin with:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Grid>
<Button Name="btn1" Content="Button" HorizontalAlignment="Left" Margin="76,76,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>
Class MainWindow
Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click
MessageBox.Show("Hi!")
End Sub
End Class
The XAML doesn't get changed, and the code-behind converts to:
using System.Windows;
namespace WpfApp1
{
public partial class MainWindow
{
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hi!");
}
}
}
From my memory ... the VB above used to be the default generated code in some older version of Visual Studio - it would add "handles" rather than dealing with it in XAML. What VB does today is the same as what C# does:
<Button Name="btn1" Content="Button" HorizontalAlignment="Left" Margin="76,76,0,0" VerticalAlignment="Top" Click="Button_Click"/>
From what I'm seeing so far, this is causing most (all?) of my conversion failures with the "handles" code.
—
Reply to this email directly, view it on GitHub<#1141 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AOKDOXSFUZDYSUCMUWAN5CT2RUVAZAVCNFSM6AAAAABQD5OKGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBTG43TEOBZGA>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
[nick2893]nick2893 left a comment (icsharpcode/CodeConverter#1141)<#1141 (comment)>
I will add one more possible solution... not promising I'll have time to dive into the code. If I begin with:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Grid>
<Button Name="btn1" Content="Button" HorizontalAlignment="Left" Margin="76,76,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>
Class MainWindow
Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click
MessageBox.Show("Hi!")
End Sub
End Class
The XAML doesn't get changed, and the code-behind converts to:
using System.Windows;
namespace WpfApp1
{
public partial class MainWindow
{
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hi!");
}
}
}
From my memory ... the VB above used to be the default generated code in some older version of Visual Studio - it would add "handles" rather than dealing with it in XAML. What VB does today is the same as what C# does:
<Button Name="btn1" Content="Button" HorizontalAlignment="Left" Margin="76,76,0,0" VerticalAlignment="Top" Click="Button_Click"/>
From what I'm seeing so far, this is causing most (all?) of my conversion failures with the "handles" code.
—
Reply to this email directly, view it on GitHub<#1141 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AOKDOXSFUZDYSUCMUWAN5CT2RUVAZAVCNFSM6AAAAABQD5OKGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBTG43TEOBZGA>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
@mjohansson1 This thread is about WPF. The code I mentioned goes to significant effort to try to fix up winforms cases already. It's a difficult problem to fully solve, so if you're seeing a remaining winforms problem, please open an issue or add to an existing closely related one with your repro. |
VB.Net input code
Erroneous output
Expected output
Details
When converting a WPF form, the Handles command in the code behind file is skipped meaning that no events ever fire.
The text was updated successfully, but these errors were encountered: