<TextBox Text="{Binding Login}" x:Name="TbxLogin" />
<PasswordBox x:Name="PasswordBox" />
<Button Content="Log in" Command="{Binding SigninCommand}"
CommandParameter="{Binding ElementName=PasswordBox}" IsDefault="True" />
public ICommand SigninCommand { get; set; }
private void Signin(object param)
{
var passwordBox = param as PasswordBox;
if (passwordBox == null)
return;
var password = passwordBox.Password;
...
}
namespace MyApp.MyNamespace.ViewModels
{
public class MyWindowModel : INotifyPropertyChanged
{
private object _foo;
public object Foo
{
get { return _foo; }
set { _foo = value; RaisePropertyChanged("Foo"); }
}
...
}
}
<Window x:Class="MyApp.MyNamespace.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModels="clr-namespace:MyApp.MyNamespace.ViewModels">
<Window.DataContext>
<viewModels:MyWindowModel x:Key="Model" />
</Window.DataContext>
<Grid>
<TextBlock Text={Binding Foo} />
</Grid>
</Window>
...
// проверяем успешность логина
if (!loginSuccess)
return;
// если всё хорошо, то создаём новое окно
var myWindow = new MyWindow();
// если нужно - что-то делаем с моделью внутри окна
var model = myWindow.DataContext as MyWindowModel;
model.Foo = new object();
// показываем новое окно
myWindow.Show();
// закрываем текущее окно логина
var window = Application.Current.Windows[0];
if (window != null)
window.Close();
<Grid Name="LayoutRoot">
<Grid.DataContext>
<MyModel SelectedItem={Binding DataContext, ElementName=MyControl}>
</Grid.DataContext>
...
var view = new ListView();
view.ItemTemplate = new DataTemplate();
view.ItemContainerStyle = new Style() { ... };
<Image Source="{Binding CurrentImage}" >
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Image.Opacity)" From="0" To="1" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
<Button Content="Next image" MouseLeftButtonDown="NextImageClick"/>
public BitmapImage CurrentImage { get; set; }
public List<BitmapImage> Images { get; set; }
private int _imageIndex = 0;
public void NextImageClick(object sender, MouseButtonEventArgs e)
{
if (_imageIndex >= Images.Count) _imageIndex = 0;
CurrentImage = Images[imageIndex];
RaisePropertyChanged("CurrentImage"); //необходимо реализовать INotifyPropertyChanged в классе модели
_imageIndex++;
}
<UserControl x:Class="..."
...
xmlns:res="clr-namespace:<namespace_проекта>.Properties"
...
<Image Source="{x:Static res:Resources.<имя_ресурса>}" />