Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » [Solved!] Need help fixing 'Cannot implicitly convert type void'
- MagicCrayon9342
-
Scratcher
1000+ posts
[Solved!] Need help fixing 'Cannot implicitly convert type void'
So, basically. when increaseClick() is ran. I want the integer ‘num’ to increase, then the text on the button reflect that. I prefer learning C# hands on, so this is where I'm starting. Here's the code.
But, upon compiling this code I get the following error.

The source of the file the error is showing
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace jdev_winui_testapp { /// <summary> /// An empty window that can be used on its own or navigated to within a Frame. /// </summary> /// public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); } int num = 0; private void increaseClick() { myButton.Content = num++; } } }
But, upon compiling this code I get the following error.

The source of the file the error is showing
#pragma checksum "C:\Users\wills\source\repos\jdev-winui-testapp\jdev-winui-testapp\jdev-winui-testapp\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "C6145C9474AF21484E0734CB03D4E767256DCC2F904DA51EED6327F22C7EEEE7" //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace jdev_winui_testapp { partial class MainWindow : global::Microsoft.UI.Xaml.Window, global::Microsoft.UI.Xaml.Markup.IComponentConnector { /// <summary> /// Connect() /// </summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 0.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public void Connect(int connectionId, object target) { switch(connectionId) { case 2: // MainWindow.xaml line 11 { this.myButton = global::WinRT.CastExtensions.As<global::Microsoft.UI.Xaml.Controls.Button>(target); ((global::Microsoft.UI.Xaml.Controls.Button)this.myButton).Click += this.increaseClick(); } break; default: break; } this._contentLoaded = true; } /// <summary> /// GetBindingConnector(int connectionId, object target) /// </summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 0.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public global::Microsoft.UI.Xaml.Markup.IComponentConnector GetBindingConnector(int connectionId, object target) { global::Microsoft.UI.Xaml.Markup.IComponentConnector returnValue = null; return returnValue; } } }
Last edited by MagicCrayon9342 (June 1, 2022 16:10:56)
- Draked12
-
Scratcher
100+ posts
[Solved!] Need help fixing 'Cannot implicitly convert type void'
weird

- MagicCrayon9342
-
Scratcher
1000+ posts
[Solved!] Need help fixing 'Cannot implicitly convert type void'
Upon using some editor-provided fixes, here's the new code.
Now, I have this error.

using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace jdev_winui_testapp { /// <summary> /// An empty window that can be used on its own or navigated to within a Frame. /// </summary> /// public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); } private int num; private void IncreaseClick() { myButton.Content = num++; } } }
Now, I have this error.

- MagicCrayon9342
-
Scratcher
1000+ posts
[Solved!] Need help fixing 'Cannot implicitly convert type void'
Solved
- Discussion Forums
- » Advanced Topics
-
» [Solved!] Need help fixing 'Cannot implicitly convert type void'