Home > Software engineering >  Stylet MVVM binded VM don't show view
Stylet MVVM binded VM don't show view

Time:08-14

As the code showed below I have the main RootViewModel and View where I placed a Content Control, and binded it to ActiveItem. My iusse is that when clicking the button the RedView is not showed, instead is drawed the text StyletTest.RedViewModel. I need to show the corresponding View in the content control when click a button(here reported only one view and view model to not be too long.) What am I missing? here the code:

RootView and RootViewModel

<Window x:Class="RootView"
        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:s="https://github.com/canton7/Stylet"
        xmlns:local="clr-namespace:StyletTest"
          xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
           
       
       
        mc:Ignorable="d"
        Title="RootView" 
        Height="300" Width="300"    >
    <Grid>
        <TextBlock>Hello, World</TextBlock>
        <Button Command="{s:Action ShowA}" Margin="50,50,50,172"     >Click me</Button>
        <ContentControl Content="{Binding ActiveItem}"  HorizontalAlignment="Left" Height="106" Margin="50,142,0,0" VerticalAlignment="Top" Width="185" />
    </Grid>
</Window>

Imports Stylet

Public Class RootViewModel
    Inherits Conductor(Of Object)
    Private windowManager As IWindowManager
    Public Sub New(ByVal windowManager As IWindowManager)
        Me.windowManager = windowManager
    End Sub
    Public Sub ShowA()
        Me.ActivateItem(New RedViewModel())
    End Sub

End Class

the RedViewModel and RedView:

Imports Stylet
Public Class RedViewModel
    Inherits screen

End Class
<UserControl x:Class="RedView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:StyletTest"
                 xmlns:s="https://github.com/canton7/Stylet"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid Background="Red">
            
    </Grid>
</UserControl>

CodePudding user response:

Solved: the Content property was the wrong one to bind.

  • Related