Skip to content

Commit

Permalink
Added data bindings samples
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Jun 25, 2014
1 parent 1c2fadb commit 7f25b5e
Show file tree
Hide file tree
Showing 98 changed files with 4,456 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<SolidColorBrush x:Key="MyBrush" Color="LightBlue"/>
</Page.Resources>
<Canvas Width="300" Height="300">
<Rectangle Canvas.Top="50" Canvas.Left="50"
Width="200" Height="200"
Fill="{StaticResource MyBrush}"/>
</Canvas>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Margin="5,5,5,5" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<CheckBox Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
x:Name="Authenticate">Authenticate with User
and Password</CheckBox>

<Label Grid.Column="0" Grid.Row="1"
HorizontalAlignment="Right">User:</Label>
<TextBox Grid.Column="1" Grid.Row="1" Text="User"
IsEnabled="{Binding ElementName=Authenticate,
Path=IsChecked}"/>

<Label Grid.Column="0" Grid.Row="2"
HorizontalAlignment="Right">Password:</Label>
<TextBox Grid.Column="1" Grid.Row="2"
IsEnabled="{Binding ElementName=Authenticate,
Path=IsChecked}"/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style TargetType="Label">
<Setter Property="FontStyle" Value="Italic"/>
</Style>
<Style TargetType="TextBox">
<Setter Property="BorderBrush" Value="Black"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Authenticate,
Path=IsChecked}" Value="True">
<Setter Property="BorderThickness" Value="2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Page.Resources>
<Grid Margin="5,5,5,5" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<CheckBox Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
x:Name="Authenticate">Authenticate with User
and Password</CheckBox>

<Label Grid.Column="0" Grid.Row="1"
HorizontalAlignment="Right">User:</Label>
<TextBox Grid.Column="1" Grid.Row="1" Text="User"
IsEnabled="{Binding ElementName=Authenticate,
Path=IsChecked}"/>

<Label Grid.Column="0" Grid.Row="2"
HorizontalAlignment="Right">Password:</Label>
<TextBox Grid.Column="1" Grid.Row="2"
IsEnabled="{Binding ElementName=Authenticate,
Path=IsChecked}"/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Margin="5,5,5,5" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<CheckBox Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
x:Name="Authenticate" Content="Authenticate with User and Password">
<CheckBox.Triggers>
<EventTrigger RoutedEvent="CheckBox.Checked">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="User"
Storyboard.TargetProperty="Background.Color"
To="Yellow" Duration="0:0:1"/>
<ColorAnimation Storyboard.TargetName="Password"
Storyboard.TargetProperty="Background.Color"
To="Yellow" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="CheckBox.Unchecked">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="User"
Storyboard.TargetProperty="Background.Color"
To="White" Duration="0:0:1"/>
<ColorAnimation Storyboard.TargetName="Password"
Storyboard.TargetProperty="Background.Color"
To="White" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</CheckBox.Triggers>
</CheckBox>

<Label Grid.Column="0" Grid.Row="1"
HorizontalAlignment="Right">User:</Label>
<TextBox Grid.Column="1" Grid.Row="1" Text="User" x:Name="User"/>

<Label Grid.Column="0" Grid.Row="2"
HorizontalAlignment="Right">Password:</Label>
<TextBox Grid.Column="1" Grid.Row="2" x:Name="Password"/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Canvas Width="300" Height="200" Background="Black">
<Ellipse Canvas.Top="0" Canvas.Left="0" Fill="LightGray"
Height="{Binding Path=Height,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType=Canvas}}">
<Ellipse.Width>
<Binding Path="Width">
<Binding.RelativeSource>
<RelativeSource Mode="FindAncestor" AncestorType="Canvas"/>
</Binding.RelativeSource>
</Binding>
</Ellipse.Width>
</Ellipse>
</Canvas>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="FreeSpaceWatcher.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="FreeSpaceWatcherWindow.xaml"
>
<Application.Resources>

</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Windows;

namespace FreeSpaceWatcher
{
public partial class App : Application
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.IO;
using System.Windows;
using System.ComponentModel;
using System.Windows.Threading;

namespace Samples
{
public class FreeSpaceInfo : DependencyObject
{
private DriveInfo currentDriveInfo = null;

public FreeSpaceInfo()
{
}

#region "Drive" dependency property
public static readonly DependencyProperty DriveProperty =
DependencyProperty.Register("Drive", typeof(string), typeof(FreeSpaceInfo),
new PropertyMetadata( new PropertyChangedCallback(OnDriveChanged)));
public string Drive
{
get { return (string)GetValue(DriveProperty); }
set { SetValue(DriveProperty, value); }
}
public static void OnDriveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
FreeSpaceInfo o = (FreeSpaceInfo)d;
// check if the drive property is empty
if (((string)e.NewValue).Length > 0)
{
// get data about the drive
o.currentDriveInfo = new DriveInfo((string)e.NewValue);
// set dependency property
d.SetValue(FreeSpaceRatioProperty,
Convert.ToDouble(o.currentDriveInfo.TotalFreeSpace) / o.currentDriveInfo.TotalSize);
}
else
// no drive has been selected -> set free space ratio to 0
d.SetValue(FreeSpaceRatioProperty, 0.0);
}
#endregion

#region "FreeSpaceRatio" dependency property
public double FreeSpaceRatio
{
// this property is read only -> no set is implemented
get { return (double)GetValue(FreeSpaceRatioProperty); }
}
public static readonly DependencyProperty FreeSpaceRatioProperty =
DependencyProperty.Register("FreeSpaceRatio", typeof(double), typeof(FreeSpaceInfo));
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AC57A4BB-BCF4-49CC-832C-2C57F2F86322}</ProjectGuid>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<RootNamespace>FreeSpaceWatcher</RootNamespace>
<AssemblyName>FreeSpaceWatcher</AssemblyName>
<WarningLevel>4</WarningLevel>
<OutputType>winexe</OutputType>
<MinFrameworkVersionRequired>3.0</MinFrameworkVersionRequired>
<IsWebBootstrapper>false</IsWebBootstrapper>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<PublishUrl>Publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Web</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>false</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>.\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<Optimize>true</Optimize>
<OutputPath>.\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="UIAutomationProvider" />
<Reference Include="UIAutomationTypes" />
<Reference Include="ReachFramework" />
<Reference Include="System.Printing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.IdentityModel" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="FreeSpaceInfo.cs" />
<Compile Include="FreeSpaceWatcherWindow.xaml.cs">
<DependentUpon>FreeSpaceWatcherWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="RatioToStringConverter.cs" />
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Page Include="FreeSpaceWatcherWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 7f25b5e

Please sign in to comment.