Listings 1: XAML • Reuse Business Object Layouts

User controls are a flexible way to provide entity specifc fragments in an application. Restricting the user control to layout and binding lets you reuse visual styling and behavior supplied in the App.xaml global resource file. WPF grids provide layout similar to HTML table layout.

<UserControl x:Class="Customer2" xmlns= 
"http://schemas.microsoft.com/winfx/2006/xaml/
presentation"
xmlns:support=
	"clr-namespace:KadGen.WpfSupport;assembly=WpfSupport"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<UserControl.CommandBindings>
	<CommandBinding Command="Save"
		CanExecute="SaveCanExecute"
		Executed="SaveExecuted"/>
</UserControl.CommandBindings>
<UserControl.Resources>
	<DataTemplate x:Key="CustomerTemplate">
		<TextBlock Text="{Binding Path=LastName}"/>
	</DataTemplate>
</UserControl.Resources>
<support:ValidationDecorator>
	<support:AuthorizationDecorator 
		Name="AuthorizationDecorator">
		<Grid>
			<Grid.RowDefinitions>
				<RowDefinition Height="70"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition/>
			</Grid.ColumnDefinitions>
			<Label Grid.Row="0" Grid.Column="0" 
				Target="{Binding 
				ElementName=SelectListBox}">
				<AccessText>Select _Customer</AccessText>
			</Label>
			<ListBox Name="SelectListBox" Margin="5" 
				ItemsSource="{Binding}"
				Grid.Row="0" Grid.Column="1"
				IsSynchronizedWithCurrentItem="True"
				ItemTemplate="{StaticResource 
				CustomerTemplate}"/>
			<Label Grid.Row="1" Grid.Column="0" 
				Target="{Binding 
				ElementName=FirstNameTextBox}" >
				<AccessText>_First Name</AccessText>
			</Label>
			<TextBox Name="FirstNameTextBox" Margin="3" 
				Grid.Row="1" Grid.Column="1" 
				Text="{Binding Path=FirstName}"/>
			<Label Grid.Row="2" Grid.Column="0"
				Target="{Binding 
				ElementName=LastNameTextBox}" >
				<AccessText>_Last Name</AccessText>
			</Label>
			<TextBox Name="LastNameTextBox"  Margin="3"
				Grid.Row="2" Grid.Column="1" 
				Text="{Binding Path=LastName}"/>
			<Label Grid.Row="3" Grid.Column="0" 
				Target="{Binding 
				ElementName=GenderComboBox}" >
				<AccessText>_Gender</AccessText>
			</Label>
			<ComboBox Name="GenderComboBox" 
				Margin="3" Grid.Row="3" Grid.Column="1" 
				Text="{Binding Path=Gender}"
				Style="{StaticResource EnumCombo}"/>
			<StackPanel Grid.Row="4" Grid.Column="0" 
				Grid.ColumnSpan="2" Margin="0,20,0,0" 
				HorizontalAlignment="Center">
			<Button Name="HelpButton" Padding="30,0,30,0"
				Click="HelpButton_Click" >Help</Button>
			<Button Padding="30,0,30,0" Command="Save"
				Content="{Binding 
				RelativeSource={RelativeSource Self}, 
				Path=Command.Text}" />
			<StackPanel Orientation="Horizontal" >
			<RadioButton Margin="5,10,5,10" 
				Click="Clerical_Click">Clerical</RadioButton>
			<RadioButton Margin="5,10,5,10" 
				Click="Manager_Click">Manager</RadioButton>
			</StackPanel>
			</StackPanel>
		</Grid>
	</support:AuthorizationDecorator>
</support:ValidationDecorator>
</UserControl>
comments powered by Disqus

Featured

  • Full Stack Hands-On Development with .NET

    In the fast-paced realm of modern software development, proficiency across a full stack of technologies is not just beneficial, it's essential. Microsoft has an entire stack of open source development components in its .NET platform (formerly known as .NET Core) that can be used to build an end-to-end set of applications.

  • .NET-Centric Uno Platform Debuts 'Single Project' for 9 Targets

    "We've reduced the complexity of project files and eliminated the need for explicit NuGet package references, separate project libraries, or 'shared' projects."

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

Subscribe on YouTube