Restore WPF .NET Framework content from WPF .NET (#144)

* Copy .NET 5 WPF content back into .NET Framework

* Add H1 heading difference for .NET

* Fix validation errors
This commit is contained in:
Andy De George
2020-12-07 13:06:20 -08:00
committed by GitHub
parent 99e90fa162
commit ffc3b77150
168 changed files with 4527 additions and 31 deletions
@@ -0,0 +1,9 @@
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:bindings"
StartupUri="CollectionView.xaml">
<Application.Resources>
</Application.Resources>
</Application>
@@ -0,0 +1,10 @@
Imports System.Collections.ObjectModel
Class Application
' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
' can be handled in this file.
Public ReadOnly Property AuctionItems As ObservableCollection(Of AuctionItem) = New ObservableCollection(Of AuctionItem)
End Class
@@ -0,0 +1,10 @@
Imports System.ComponentModel
Public Class AuctionItem
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public CurrentPrice As Integer
End Class
@@ -0,0 +1,33 @@
<Window x:Class="CollectionView"
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:local="clr-namespace:bindings"
mc:Ignorable="d"
Title="CollectionView" Height="450" Width="800" Loaded="Window_Loaded">
<!-- <CollectionView> -->
<Window.Resources>
<CollectionViewSource
Source="{Binding Source={x:Static Application.Current}, Path=AuctionItems}"
x:Key="listingDataView" />
</Window.Resources>
<!-- </CollectionView> -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel>
<CheckBox Checked="AddSortCheckBox_Checked">Add Sorting</CheckBox>
<CheckBox Checked="AddFilteringCheckBox_Checked">Add Filtering</CheckBox>
<CheckBox Checked="AddGroupingCheckBox_Checked">Add Grouping</CheckBox>
</StackPanel>
<!-- <ListBoxCollectionView> -->
<ListBox Name="Master" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
ItemsSource="{Binding Source={StaticResource listingDataView}}" />
<!-- </ListBoxCollectionView> -->
</Grid>
</Window>
@@ -0,0 +1,58 @@
Imports System.ComponentModel
Public Class CollectionView
Public listingDataView As CollectionViewSource
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
listingDataView = CType(Resources("listingDataView"), CollectionViewSource)
End Sub
' <ListingViewFilter>
Private Sub AddFilteringCheckBox_Checked(sender As Object, e As RoutedEventArgs)
Dim checkBox = DirectCast(sender, CheckBox)
If checkBox.IsChecked = True Then
AddHandler listingDataView.Filter, AddressOf ListingDataView_Filter
Else
RemoveHandler listingDataView.Filter, AddressOf ListingDataView_Filter
End If
End Sub
' </ListingViewFilter>
Private Sub AddGroupingCheckBox_Checked(sender As Object, e As RoutedEventArgs)
' <ListingGroupCheck>
' This groups the items in the view by the property "Category"
Dim groupDescription = New PropertyGroupDescription()
groupDescription.PropertyName = "Category"
listingDataView.GroupDescriptions.Add(groupDescription)
' </ListingGroupCheck>
End Sub
' <FilterEvent>
Private Sub ListingDataView_Filter(sender As Object, e As FilterEventArgs)
' Start with everything excluded
e.Accepted = False
Dim product As AuctionItem = TryCast(e.Item, AuctionItem)
If product IsNot Nothing Then
' Only include products with prices lower than 25
If product.CurrentPrice < 25 Then e.Accepted = True
End If
End Sub
' </FilterEvent>
' <AddSortChecked>
Private Sub AddSortCheckBox_Checked(sender As Object, e As RoutedEventArgs)
' Sort the items first by Category And then by StartDate
listingDataView.SortDescriptions.Add(New SortDescription("Category", ListSortDirection.Ascending))
listingDataView.SortDescriptions.Add(New SortDescription("StartDate", ListSortDirection.Ascending))
End Sub
' </AddSortChecked>
End Class
@@ -0,0 +1,14 @@
' <ColorBrushConverter>
<ValueConversion(GetType(Color), GetType(SolidColorBrush))>
Public Class ColorBrushConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim color As Color = CType(value, Color)
Return New SolidColorBrush(color)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return Nothing
End Function
End Class
' </ColorBrushConverter>
@@ -0,0 +1,30 @@
Imports System.Globalization
' <FutureDateRule>
Public Class FutureDateRule
Inherits ValidationRule
Public Overrides Function Validate(value As Object, cultureInfo As CultureInfo) As ValidationResult
Dim inputDate As Date
' Test if date is valid
If Date.TryParse(value.ToString, inputDate) Then
' Date is not in the future, fail
If Date.Now > inputDate Then
Return New ValidationResult(False, "Please enter a date in the future.")
End If
Else
' // Date Is Not a valid date, fail
Return New ValidationResult(False, "Value is not a valid date.")
End If
' Date is valid and in the future, pass
Return ValidationResult.ValidResult
End Function
End Class
' </FutureDateRule>
@@ -0,0 +1,12 @@
<Window x:Class="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:local="clr-namespace:bindings"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>
@@ -0,0 +1,3 @@
Class MainWindow
End Class
@@ -0,0 +1,19 @@
Imports bindings.SDKSample
Public Class ManualBinding
Public myText As TextBox
Public Sub BindTextBox()
' <CodeOnlyBinding>
' Make a New source
Dim myDataObject As New MyData
Dim myBinding As New Binding("ColorName")
myBinding.Source = myDataObject
' Bind the data source to the TextBox control's Text dependency property
myText.SetBinding(TextBlock.TextProperty, myBinding)
' </CodeOnlyBinding>
End Sub
End Class
@@ -0,0 +1,9 @@
Namespace SDKSample
Public Class MyData
Public ReadOnly Property ColorName As String = "Red"
End Class
End Namespace
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>bindings</RootNamespace>
<UseWpf>true</UseWpf>
</PropertyGroup>
<ItemGroup>
<Import Include="System.Windows" />
<Import Include="System.Windows.Controls" />
<Import Include="System.Windows.Data" />
<Import Include="System.Windows.Documents" />
<Import Include="System.Windows.Input" />
<Import Include="System.Windows.Media" />
<Import Include="System.Windows.Media.Imaging" />
<Import Include="System.Windows.Navigation" />
<Import Include="System.Windows.Shapes" />
</ItemGroup>
</Project>