0
votes

I have a program with the following schema.

The program start with a login, once the user puts the name and password it directs to the main window (no problem passing the values there as it is between forms). This windows uses a MVVM schema to load the ContentControl necessary in that moment.

<Window.Resources>
    <DataTemplate ...>
    </DataTemplate>  (several times)
</Window.Resources>
<DockPanel>
    <Menu DockPanel.Dock="Top" ItemsSource="{Binding MenuItems}">
        <Menu.ItemContainerStyle>
            <Style TargetType="{x:Type MenuItem}">
                <Setter Property="Command" Value="{Binding Command}" />
            </Style>
        </Menu.ItemContainerStyle>
        <Menu.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Path=MenuItems}">
                <TextBlock Text="{Binding Header}"/>
            </HierarchicalDataTemplate>
        </Menu.ItemTemplate>
    </Menu>
    <ContentControl Content="{Binding CurrentPageViewModel}" >

    </ContentControl>
</DockPanel>

As you can see from the code, it has a binded menu (wich does not change) and a ContentControl, which calls a UserControl depending on what button has been presed on the menu. The ContentControl is binded and uses a MVVM model to load the UserControl.

The problem is that the UserControl is not using a MVVM schema (only the loading part uses the MVVM). They are directly operating in c# using a direct WPF model (.cs and .xaml), so the UserControl ViewModel does not bind anything in the Model UserControl.

I want to find a way to pass the login information to the called UserControl. In a way that every time it changes the ContentControl, the new UserControl will have acces to the login data.

Is there any way to create a global-like variable that can be posted by the login or the main window, adn read by each of the UserControls?

1
Of course. Just use a public static variable in some class.Rekshino
It is not static, as i said is the login and password. the problem is the connection between them there is not a direct declaration between my main and the content as it uses xaml datatemplate.user3469873
In each DataTemplate you can bind to the some static property.Rekshino

1 Answers

0
votes

It is not exactly what i wanted but i did the trick by using the project properties.

I set it in the loggin and get it in the window i want.

    object  myProperty = App.Current.Properties["Test"];