mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-06 23:43:07 +02:00
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:
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="bindings.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:bindings"
|
||||
StartupUri="DataValidation.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public ObservableCollection<AuctionItem> AuctionItems { get; } = new ObservableCollection<AuctionItem>();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
public class AuctionItem : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public int CurrentPrice { get; set; } = 0;
|
||||
|
||||
public int StartPrice { get; set; } = 50;
|
||||
|
||||
public DateTime StartDate { get; set; } = DateTime.Now;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<UserControl x:Class="bindings.AutoConvertPropertyToColor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:bindings"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<StackPanel>
|
||||
<!-- <BindAutoConvertColor> -->
|
||||
<DockPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:SDKSample">
|
||||
<DockPanel.Resources>
|
||||
<c:MyData x:Key="myDataSource"/>
|
||||
</DockPanel.Resources>
|
||||
<DockPanel.DataContext>
|
||||
<Binding Source="{StaticResource myDataSource}"/>
|
||||
</DockPanel.DataContext>
|
||||
<Button Background="{Binding Path=ColorName}"
|
||||
Width="150" Height="30">
|
||||
I am bound to be RED!
|
||||
</Button>
|
||||
</DockPanel>
|
||||
<!-- </BindAutoConvertColor> -->
|
||||
<!-- <BindAutoConvertColorCompactBinding> -->
|
||||
<DockPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:SDKSample">
|
||||
<DockPanel.Resources>
|
||||
<c:MyData x:Key="myDataSource"/>
|
||||
</DockPanel.Resources>
|
||||
<Button Background="{Binding Source={StaticResource myDataSource}, Path=ColorName}"
|
||||
Width="150" Height="30">
|
||||
I am bound to be RED!
|
||||
</Button>
|
||||
</DockPanel>
|
||||
<!-- </BindAutoConvertColorCompactBinding> -->
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DockPanelBindRedExample.xaml
|
||||
/// </summary>
|
||||
public partial class AutoConvertPropertyToColor : UserControl
|
||||
{
|
||||
public AutoConvertPropertyToColor()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
<Window x:Class="bindings.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:src="clr-namespace:bindings"
|
||||
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.Resources>
|
||||
<!-- <AuctionItemDataTemplate> -->
|
||||
<DataTemplate DataType="{x:Type src:AuctionItem}">
|
||||
<Border BorderThickness="1" BorderBrush="Gray"
|
||||
Padding="7" Name="border" Margin="3" Width="500">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition Width="86"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Polygon Grid.Row="0" Grid.Column="0" Grid.RowSpan="4"
|
||||
Fill="Yellow" Stroke="Black" StrokeThickness="1"
|
||||
StrokeLineJoin="Round" Width="20" Height="20"
|
||||
Stretch="Fill"
|
||||
Points="9,2 11,7 17,7 12,10 14,15 9,12 4,15 6,10 1,7 7,7"
|
||||
Visibility="Hidden" Name="star"/>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0,0,8,0"
|
||||
Name="descriptionTitle"
|
||||
Style="{StaticResource smallTitleStyle}">Description:</TextBlock>
|
||||
|
||||
<TextBlock Name="DescriptionDTDataType" Grid.Row="0" Grid.Column="2"
|
||||
Text="{Binding Path=Description}"
|
||||
Style="{StaticResource textStyleTextBlock}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0,0,8,0"
|
||||
Name="currentPriceTitle"
|
||||
Style="{StaticResource smallTitleStyle}">Current Price:</TextBlock>
|
||||
|
||||
<StackPanel Grid.Row="1" Grid.Column="2" Orientation="Horizontal">
|
||||
<TextBlock Text="$" Style="{StaticResource textStyleTextBlock}"/>
|
||||
<TextBlock Name="CurrentPriceDTDataType"
|
||||
Text="{Binding Path=CurrentPrice}"
|
||||
Style="{StaticResource textStyleTextBlock}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Path=SpecialFeatures}">
|
||||
<DataTrigger.Value>
|
||||
<src:SpecialFeatures>Color</src:SpecialFeatures>
|
||||
</DataTrigger.Value>
|
||||
<DataTrigger.Setters>
|
||||
<Setter Property="BorderBrush" Value="DodgerBlue" TargetName="border" />
|
||||
<Setter Property="Foreground" Value="Navy" TargetName="descriptionTitle" />
|
||||
<Setter Property="Foreground" Value="Navy" TargetName="currentPriceTitle" />
|
||||
<Setter Property="BorderThickness" Value="3" TargetName="border" />
|
||||
<Setter Property="Padding" Value="5" TargetName="border" />
|
||||
</DataTrigger.Setters>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=SpecialFeatures}">
|
||||
<DataTrigger.Value>
|
||||
<src:SpecialFeatures>Highlight</src:SpecialFeatures>
|
||||
</DataTrigger.Value>
|
||||
<Setter Property="BorderBrush" Value="Orange" TargetName="border" />
|
||||
<Setter Property="Foreground" Value="Navy" TargetName="descriptionTitle" />
|
||||
<Setter Property="Foreground" Value="Navy" TargetName="currentPriceTitle" />
|
||||
<Setter Property="Visibility" Value="Visible" TargetName="star" />
|
||||
<Setter Property="BorderThickness" Value="3" TargetName="border" />
|
||||
<Setter Property="Padding" Value="5" TargetName="border" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
<!-- </AuctionItemDataTemplate> -->
|
||||
</Grid.Resources>
|
||||
<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>
|
||||
|
||||
<!-- <ListBoxContentControl> -->
|
||||
<!-- <ListBoxCollectionView> -->
|
||||
<ListBox Name="Master" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
|
||||
ItemsSource="{Binding Source={StaticResource listingDataView}}" />
|
||||
<!-- </ListBoxCollectionView> -->
|
||||
<ContentControl Name="Detail" Grid.Row="3" Grid.ColumnSpan="3"
|
||||
Content="{Binding Source={StaticResource listingDataView}}"
|
||||
ContentTemplate="{StaticResource detailsProductListingTemplate}"
|
||||
Margin="9,0,0,0"/>
|
||||
<!-- </ListBoxContentControl> -->
|
||||
</Grid>
|
||||
</Window>
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CollectionView.xaml
|
||||
/// </summary>
|
||||
public partial class CollectionView : Window
|
||||
{
|
||||
public CollectionViewSource listingDataView;
|
||||
|
||||
public CollectionView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
listingDataView = (CollectionViewSource)Resources["listingDataView"];
|
||||
}
|
||||
|
||||
// <ListingViewFilter>
|
||||
private void AddFilteringCheckBox_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (((CheckBox)sender).IsChecked == true)
|
||||
listingDataView.Filter += ListingDataView_Filter;
|
||||
else
|
||||
listingDataView.Filter -= ListingDataView_Filter;
|
||||
}
|
||||
// </ListingViewFilter>
|
||||
|
||||
private void AddGroupingCheckBox_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// <ListingGroupCheck>
|
||||
// This groups the items in the view by the property "Category"
|
||||
var groupDescription = new PropertyGroupDescription();
|
||||
groupDescription.PropertyName = "Category";
|
||||
listingDataView.GroupDescriptions.Add(groupDescription);
|
||||
// </ListingGroupCheck>
|
||||
}
|
||||
|
||||
// <FilterEvent>
|
||||
private void ListingDataView_Filter(object sender, FilterEventArgs e)
|
||||
{
|
||||
// Start with everything excluded
|
||||
e.Accepted = false;
|
||||
|
||||
// Only inlcude items with a price less than 25
|
||||
if (e.Item is AuctionItem product && product.CurrentPrice < 25)
|
||||
e.Accepted = true;
|
||||
}
|
||||
// </FilterEvent>
|
||||
|
||||
// <AddSortChecked>
|
||||
private void AddSortCheckBox_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
// </AddSortChecked>
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
// <ColorBrushConverter>
|
||||
[ValueConversion(typeof(Color), typeof(SolidColorBrush))]
|
||||
public class ColorBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
Color color = (Color)value;
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// </ColorBrushConverter>
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<Window x:Class="bindings.DataValidation"
|
||||
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"
|
||||
xmlns:src="clr-namespace:bindings"
|
||||
mc:Ignorable="d"
|
||||
Title="DataValidation" Height="450" Width="800">
|
||||
<Window.Resources>
|
||||
<!-- <ControlTemplate> -->
|
||||
<ControlTemplate x:Key="validationTemplate">
|
||||
<DockPanel>
|
||||
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
|
||||
<AdornedElementPlaceholder/>
|
||||
</DockPanel>
|
||||
</ControlTemplate>
|
||||
<!-- </ControlTemplate> -->
|
||||
<!-- <TextBoxStyle> -->
|
||||
<Style x:Key="textStyleTextBox" TargetType="TextBox">
|
||||
<Setter Property="Foreground" Value="#333333" />
|
||||
<Setter Property="MaxLength" Value="40" />
|
||||
<Setter Property="Width" Value="392" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Validation.HasError" Value="true">
|
||||
<Setter Property="ToolTip"
|
||||
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<!-- </TextBoxStyle> -->
|
||||
<src:DateConverter x:Key="dateConverter" />
|
||||
<src:AuctionItem x:Key="item" />
|
||||
</Window.Resources>
|
||||
|
||||
<Grid DataContext="{StaticResource item}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
|
||||
<ColumnDefinition Width="779*"/>
|
||||
<ColumnDefinition Width="21*"/>
|
||||
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- <TextboxStartPrice> -->
|
||||
<TextBox Name="StartPriceEntryForm" Grid.Row="2"
|
||||
Style="{StaticResource textStyleTextBox}" Margin="8,5,0,5" Grid.ColumnSpan="2">
|
||||
<TextBox.Text>
|
||||
<Binding Path="StartPrice" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<ExceptionValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<!-- </TextboxStartPrice> -->
|
||||
|
||||
<!-- <TextboxStartDate> -->
|
||||
<TextBox Name="StartDateEntryForm" Grid.Row="3"
|
||||
Validation.ErrorTemplate="{StaticResource validationTemplate}"
|
||||
Style="{StaticResource textStyleTextBox}" Margin="8,5,0,5" Grid.ColumnSpan="2">
|
||||
<TextBox.Text>
|
||||
<Binding Path="StartDate" UpdateSourceTrigger="PropertyChanged"
|
||||
Converter="{StaticResource dateConverter}" >
|
||||
<Binding.ValidationRules>
|
||||
<src:FutureDateRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<!-- </TextboxStartDate> -->
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataValidation.xaml
|
||||
/// </summary>
|
||||
public partial class DataValidation : Window
|
||||
{
|
||||
public DataValidation()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
[ValueConversion(typeof(DateTime), typeof(string))]
|
||||
public class DateConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
DateTime date = (DateTime)value;
|
||||
return date.ToShortDateString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
string strValue = value.ToString();
|
||||
DateTime resultDateTime;
|
||||
if (DateTime.TryParse(strValue, out resultDateTime))
|
||||
{
|
||||
return resultDateTime;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<UserControl x:Class="bindings.EmptyBinding"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:bindings"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<StackPanel>
|
||||
<!-- <EmptyBinding> -->
|
||||
<ListBox ItemsSource="{Binding}"
|
||||
IsSynchronizedWithCurrentItem="true"/>
|
||||
<!-- </EmptyBinding> -->
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for EmptyBinding.xaml
|
||||
/// </summary>
|
||||
public partial class EmptyBinding : UserControl
|
||||
{
|
||||
public EmptyBinding()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
// <FutureDateRule>
|
||||
public class FutureDateRule : ValidationRule
|
||||
{
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
// Test if date is valid
|
||||
if (DateTime.TryParse(value.ToString(), out DateTime date))
|
||||
{
|
||||
// Date is not in the future, fail
|
||||
if (DateTime.Now > date)
|
||||
return new ValidationResult(false, "Please enter a date in the future.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Date is not a valid date, fail
|
||||
return new ValidationResult(false, "Value is not a valid date.");
|
||||
}
|
||||
|
||||
// Date is valid and in the future, pass
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
// </FutureDateRule>
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<Window x:Class="bindings.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>
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using SDKSample;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
class ManualBinding
|
||||
{
|
||||
public TextBox myText;
|
||||
|
||||
public void BindTextBox()
|
||||
{
|
||||
// <CodeOnlyBinding>
|
||||
// Make a new source
|
||||
var myDataObject = new MyData();
|
||||
var myBinding = new Binding("ColorName")
|
||||
{
|
||||
Source = myDataObject
|
||||
};
|
||||
|
||||
// Bind the data source to the TextBox control's Text dependency property
|
||||
myText.SetBinding(TextBlock.TextProperty, myBinding);
|
||||
// </CodeOnlyBinding>
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SDKSample
|
||||
{
|
||||
class MyData
|
||||
{
|
||||
public string ColorName => "Red";
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace bindings
|
||||
{
|
||||
public enum SpecialFeatures
|
||||
{
|
||||
None,
|
||||
Color,
|
||||
Highlight
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWpf>true</UseWpf>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
+9
@@ -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>
|
||||
+10
@@ -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
|
||||
+10
@@ -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
|
||||
+33
@@ -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>
|
||||
+58
@@ -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
|
||||
+14
@@ -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>
|
||||
+30
@@ -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>
|
||||
+12
@@ -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>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Class MainWindow
|
||||
|
||||
End Class
|
||||
+19
@@ -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
|
||||
+22
@@ -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>
|
||||
Reference in New Issue
Block a user