Binding To a Parent Element in UWP and WinUI 3
Posted: January 20, 2022 Filed under: MVVM, UWP, WinUI, XAML | Tags: MVVM, UWP, Windows App SDK, WinUI, XAML 2 CommentsIn a WPF application, it’s easy to bind to a property of a parent element in the visual tree by setting the RelativeSource
property of the binding to a RelativeSource object that specifies the type of ancestor to bind to.
Read »
Implicit Data Templates in UWP
Posted: March 25, 2017 Filed under: C#, UWP, XAML | Tags: C#, UWP, XAML 1 CommentIn WPF the use of implicit data templates without an x:Key
makes it easy to associate a template with a particular type of object. You just set the DataType
property of the DataTemplate
to the corresponding type and the template is then applied automatically to all instances of that particular type.
The Universal Windows Platform (UWP) however has no concept of implicit data templates. Each DataTemplate
that you define in a UWP app must have an x:Key
attribute and it must be set to a string
value.
Read »
Disabling selection of some items in a UWP ListView
Posted: February 28, 2016 Filed under: MVVM, UWP, XAML | Tags: MVVM, UWP, XAML 2 CommentsSetting the SelectionMode property of a ListView control to Multiple (Windows.UI.Xaml.Controls.ListViewSelectionMode.Multiple) in a Universal Windows Platform (UWP) app enables you to select several items by checking an automatically generated CheckBox element for each item that you want to select:
Tabbing between items in a ListBox in WPF
Posted: August 13, 2014 Filed under: WPF, XAML | Tags: C#, MVVM, WPF, XAML Leave a commentThis post explains what XAML changes you need to make in order to be able to navigate between elements that are the defined in the ItemsTemplate of a WPF ListBox using the TAB key on the keyboard.
Read »
Changing the background colour of a ComboBox in WPF on Windows 8
Posted: April 30, 2014 Filed under: WPF, XAML | Tags: Visual Studio, WPF, XAML 6 CommentsThis post explains how to change the colours of a ComboBox in a WPF application by overriding the control’s default template in XAML using Visual Studio 2012 or 2013.
Read »
Handling events in an MVVM WPF application
Posted: June 30, 2013 Filed under: MVVM, WPF, XAML | Tags: MVVM, WPF, XAML 21 CommentsIn a WPF application that uses the MVVM (Model-View-ViewModel) design pattern, the view model is the component that is responsible for handling the application’s presentation logic and state. This means that the view’s code-behind file should contain no code to handle events that are raised from any user interface (UI) element such as a Button or a ComboBox nor should it contain any domain specific logic.
Ideally, the code-behind of a view – typically a Window or a UserControl – contains only a constructor that calls the InitializeComponent method and perhaps some additional code to control or interact with the view layer that is difficult or inefficient to express in XAML, e.g. complex animations.
Read »