Я начинаю с приложения wpf. И я пытаюсь практиковать патрон MVVM. У меня возникли проблемы с привязкой datacontext к Usercontrol.Binding datacontext Usercontrol
<UserControl x:Class="Test.Views.Login.Identifer"
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:vm="clr-namespace:Test.ViewModels"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<UserControl.DataContext>
<vm:Login/>
</UserControl.DataContext>
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Name="user"></TextBox>
<TextBox Grid.Row="1" Name="password"></TextBox>
</Grid>
это мой UserControl и Войти мой класс, который я хочу, чтобы привязать к моей DataContext. Я поставил этот UserControl в моем PhonApplicationPage:
<phone:PhoneApplicationPage
x:Class="Test.Views.Login.Login"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Views="clr-namespace:Test.Views.Login"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot est la grille racine où tout le contenu de la page est placé-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Views:Identifer></Views:Identifer>
</Grid>
И я собираюсь finsih с моим Вход класса:
using Test.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test.ViewModels
{
class Login : MyNotifyPropertyChanged
{
public Client client_ { get; set; }
public Login()
{
client_ = new Client();
}
}
}
И у меня следующее сообщение об ошибке: ERREUR 1 Невозможно создать экземпляр типа «Test.ViewModels.Login» [Строка: 14 Позиция: 19]
Спасибо за помощь.
Лол, спасибо. – king