Setting the
DataContext of a View to a ViewModel can be done in various ways. It can be done in the
constructor of the View
public LoginView()
{
InitializeComponent();
DataContext = new LoginViewModel();
}
or
public LoginView(LoginViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
}
or directly in the
XAML
<UserControl x:Class="MvvmPassword.LoginView"
x:Name="This"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MvvmPassword">
<UserControl.Resources>
<local:LoginViewModel x:Key="ViewModel" />
</UserControl.Resources>
<Grid DataContext="{Binding Source={StaticResource ViewModel}}">
...
</Grid>
</UserControl>
or
<UserControl x:Class="MvvmPassword.LoginView"
x:Name="This"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MvvmPassword">
<UserControl.DataContext>
<local:LoginViewModel x:Name="ViewModel" />
</UserControl.DataContext>
<Grid>
...
</Grid>
</UserControl>
This only works if you have a default parameter-less constructor.
ReplyDelete8D2CC
ReplyDeletebedava görüntülü sohbet sitesi
sakarya en iyi görüntülü sohbet uygulaması
canli goruntulu sohbet siteleri
erzurum görüntülü canlı sohbet
diyarbakır ücretsiz görüntülü sohbet
siirt en iyi görüntülü sohbet uygulaması
mobil sohbet sitesi
bedava sohbet
kırşehir yabancı görüntülü sohbet
CA7B6
ReplyDeletesushi
safepal
arbitrum
arculus
shiba
metamask
onekey
poocoin
ellipal
58883
ReplyDeletephantom wallet
uwulend finance
layerzero
pancakeswap
zkswap
eigenlayer
bscpad
sushiswap
spookyswap