Share via

CommunityToolkit (apparently ) not generating internal code

RogerSchlueter-7899 1,671 Reputation points
2023-02-06T20:19:06.5733333+00:00

I've decided to give the CommunityToolkit a try but my code and the parts of the Toolkit are not making a connection.

Here's the relevant parts of my MainWi8ndow:

<Window
    x:Class="MainWindow"

    <Window.DataContext>
        <self:MainWindowVM />
    </Window.DataContext>

    <Label
        Content="{Binding Path=FirstLabel}" />

    <Button
        Command="{Binding Path=ExitMe}"
        Content="Exit" />
</Window>

And the View Model:

Imports CommunityToolkit.Mvvm.ComponentModel
Imports CommunityToolkit.Mvvm.Input

Partial Public Class MainWindowVM
    Inherits ObservableObject
    ....
<RelayCommand>
Private Sub ExitMe()
    Windows.Application.Current.Shutdown()
End Sub
    ....
<ObservableProperty>
Private FirstLabel As String
....
<End Class

At run-time I get two error messages:

ExitMe' property not found on 'object' ''MainWindowVM'

That is obviously a correct error message but that is the way it is done in an example I am using as a guide.

BindingExpression path error: 'FirstLabel' property not found on 'object' ''MainWindowVM'

That one I don't understand. My understanding is that the toolkit generates the Public property from the private declaration. Is that not correct?

Thanks in advance for the help.

Developer technologies | Windows Presentation Foundation
Developer technologies | VB
0 comments No comments

2 answers

Sort by: Most helpful
  1. RogerSchlueter-7899 1,671 Reputation points
    2023-02-09T02:44:28.15+00:00

    Using the toolkit in the manner shown by my code is only possible with C#.


  2. Hui Liu-MSFT 48,711 Reputation points Microsoft External Staff
    2023-02-07T03:17:25.8866667+00:00

    You could use the following code.

    
    Imports CommunityToolkit.Mvvm.ComponentModel
    Imports CommunityToolkit.Mvvm.Input
    
    Class MainWindow
    
    End Class
    
    Partial Public Class MainWindowVM
        Inherits ObservableObject
    
        Public Sub New()
            Me.FirstLabel = "default value..."
            Me.ExitMe = New RelayCommand(AddressOf exMe)
        End Sub
    
        <ObservableProperty>
        Private fLabel As String
    
        Public Property FirstLabel As String
    
    
        Private Sub Save()
            Me.fLabel = FirstLabel
    
    
        End Sub
    
    
    
        <RelayCommand>
        Private Sub exMe()
            Windows.Application.Current.Shutdown()
        End Sub
    
        Public ReadOnly Property ExitMe As ICommand
    
    
    End Class
    
    
    

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.