ApplicationCommands
cannot be used in MVVM.InputBinding.CommandParameter
is notDependencyProperty
so cannot pass a UI.- Use
Behavior
to accessKeyEventArgs
orMouseEventArgs
.KeyBinding
cannot accessKeyEventArgs
. *MouseBinding
cannot accessMouseEventArgs
.
DataTemplate
is how to display an object in GUI and analogous toToString()
in CLI.- How to make the UI thread wait until a non-UI thread is done.
await Task.Run(() => IamNonUiThread());
- Omit
Grid.Row="0"
andGrid.Column="0"
as they are default. - Omit
Width="*"
onColumnDefinition
andHeight="*"
onRowDefinition
as star is default. - A rather than B
- Use
{Binding Property1}
rather than{Binding Path=Property1}
asPath=
is optional. - Use attribute syntax rather than property element syntax
- For example, use
<Button Content="Content1" />
rather than<Button>Content1\<Button/>
- For example, use
- Use
- Bind the following method to
PreviewMouseLeftButtonDown
rather thanMouseLeftButtonDown
.MouseLeftButtonDown
is never called.
void CheckIfNewVersionAvailable(object sender, MouseButtonEventArgs e)
{
if (IsLatestVersion(...))
{
return;
}
if (MessageBox.Show("New version is available. Restart?", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
// Start the new version and close self.
}
// Not relay to the Click event.
e.Handled = true;
}
Name | Description |
---|---|
Binding source | object |
Binding target | UI |
"{Binding RelativeSource={RelativeSource Self}}"
<TextBox Name="TextBox1" />
<TextBox Name="TextBox2" Text="{Binding ElementName=TextBox1, Path=Text}" />