Почему не работает?
View
<Window x:Class="Films.MainWindow"
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:mvvm="clr-namespace:Films.Classes.MVVM"
ResizeMode="NoResize"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<mvvm:MainViewModel/>
</Window.DataContext>
<Grid Height="Auto" Width="Auto">
<Grid.Background>
<ImageBrush x:Name="GridImage" Stretch="Fill" ImageSource="{Binding FilmViewModel.FilmPicture}"></ImageBrush>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" MinWidth="100" MaxWidth="740"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid x:Name="MainGrid"
Grid.Column="0"
Height="Auto" Background="#2D474646">
<Border Height="250" Width="280" HorizontalAlignment="Center" VerticalAlignment="Center"
BorderThickness="1,1,1,1" CornerRadius="30,30,30,30" Background="#4C474646">
<Grid DataContext="{Binding model}">
<Button Content="Acscess" Width="90" Height="27" Command="{Binding SignUp}" CommandParameter="{Binding ElementName=Password}" x:Name="Autorization" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,45,0,0" />
<Button Content="Go by Guest" Width="76" Command="{Binding SignByGhost}" x:Name="Guest" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,130,0,0"/>
<TextBox Text="{Binding Login}" Height="34" Width="171" Margin="0,0,0,100" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<PasswordBox x:Name="Password" Width="136" Height="25" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,29"/>
</Grid>
</Border>
<Border HorizontalAlignment="Left" VerticalAlignment="Bottom"
Height="120" Width="120" BorderThickness="1,1,1,1" CornerRadius="0,100,0,0" Background="#B2FF0000">
<TextBlock Text="{Binding FilmViewModel.FilmName}" TextWrapping="WrapWithOverflow"
VerticalAlignment="Bottom" Height="65" Width="80" Margin="0,0,17,10" Background="#00000000"
FlowDirection="LeftToRight" FontSize="15" Foreground="#FFF9F9F9" HorizontalAlignment="Center"/>
</Border>
</Grid>
<GridSplitter x:Name="Splinter" Grid.Column="0" Width="4" Height="Auto" HorizontalAlignment="Right" Margin="0,1,2,0" >
<GridSplitter.Effect>
<DropShadowEffect Direction="152" BlurRadius="10" ShadowDepth="2" Color="Gray" Opacity="1"></DropShadowEffect>
</GridSplitter.Effect>
</GridSplitter>
<Grid x:Name="SettingsGrid"
Grid.Column="1"
HorizontalAlignment="Stretch">
<Button VerticalAlignment="Top" HorizontalAlignment="Stretch"
Height="40">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="15"/>
</Style>
</Button.Resources>
</Button>
</Grid>
</Grid>
</Window>
Проблема тут
<Grid DataContext="{Binding model}">
<Button Content="Acscess" Width="90" Height="27" Command="{Binding SignUp}" CommandParameter="{Binding ElementName=Password}" x:Name="Autorization" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,45,0,0" />
<Button Content="Go by Guest" Width="76" Command="{Binding SignByGhost}" x:Name="Guest" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,130,0,0"/>
<TextBox Text="{Binding Login}" Height="34" Width="171" Margin="0,0,0,100" FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<PasswordBox x:Name="Password" Width="136" Height="25" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,29"/>
</Grid>
Я пробовал без DataConext
, через объект указывать model.
, не работает.
Я проверяю роботоспособность кликом на кнопку, на неё должно выводиться окошко.
MainViewModel:
class MainViewModel : INPC
{
public AutorizationViewModel model
{
get;set;
}
}
AutorizationViewModel(2ая ViewModel)
class AutorizationViewModel
{
private string login;
public string Login
{
get => login;
set
{
login = value;
}
}
public ICommand SignUp
{
get
{
return new DelegateCommand((obj) =>
{
System.Windows.MessageBox.Show("CALAM");
});
}
}
public ICommand SignByGhost
{
get
{
return new DelegateCommand((obj) =>
{
// Залетаем в новое окно
System.Windows.MessageBox.Show("CALAM2");
});
}
}
private string GetPassword(object passwordObject)
{
var passwordBox = passwordObject as PasswordBox;
if (passwordBox == null)
return "";
return passwordBox.Password;
}
}
model
не инициализирован (null
)? Ну или вы его инициализируете уже после привязки основной VM. Вообще, у вас тут куча нарушений MVVM и других аспектов, советую исправить их.