ADD MVVM Sample.

NTFY-24

git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@198 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
Philipp Sumi
2013-11-22 23:37:09 +00:00
parent 6ae24d3c23
commit e0f4d731ca
9 changed files with 180 additions and 6 deletions

View File

@@ -3,11 +3,11 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="NotifyIcon Samples" Title="NotifyIcon Samples"
Height="563" Height="626"
Width="703" Width="703"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> mc:Ignorable="d" ResizeMode="NoResize">
<Grid <Grid
Hyperlink.RequestNavigate="OnNavigationRequest"> Hyperlink.RequestNavigate="OnNavigationRequest">
<Grid.Background> <Grid.Background>
@@ -118,12 +118,11 @@
x:Name="btnToolTipControl" x:Name="btnToolTipControl"
Click="btnToolTipControl_Click" /> Click="btnToolTipControl_Click" />
<TextBlock <TextBlock
Margin="0,50,328.76,0" Margin="255.31,50,0,0"
VerticalAlignment="Top" VerticalAlignment="Top"
FontWeight="Bold" FontWeight="Bold"
TextWrapping="Wrap" TextWrapping="Wrap"
HorizontalAlignment="Right" HorizontalAlignment="Left" Width="110.93">
d:LayoutOverrides="HorizontalAlignment, Width">
<Run <Run
Text="Showcase Sample:" /> Text="Showcase Sample:" />
</TextBlock> </TextBlock>
@@ -207,7 +206,7 @@
Height="1" Height="1"
Data="M11,517 L561.07363,517" Opacity="0.33" /> Data="M11,517 L561.07363,517" Opacity="0.33" />
<Button <Button
Margin="11,429,0,0" Margin="10,466,0,0"
Content="Events" Content="Events"
VerticalAlignment="Top" VerticalAlignment="Top"
Height="27" Height="27"
@@ -222,6 +221,15 @@
Height="27" Height="27"
x:Name="btnDataBinding" x:Name="btnDataBinding"
Click="btnDataBinding_Click" /> Click="btnDataBinding_Click" />
<Button
HorizontalAlignment="Left"
Margin="10,429,0,0"
Width="164"
Content="MVVM"
VerticalAlignment="Top"
Height="27"
x:Name="btnMvvm"
Click="btnMvvm_Click" />
</Grid> </Grid>
</Window> </Window>

View File

@@ -6,6 +6,7 @@ using Samples.Tutorials.Commands;
using Samples.Tutorials.ContextMenus; using Samples.Tutorials.ContextMenus;
using Samples.Tutorials.DataBinding; using Samples.Tutorials.DataBinding;
using Samples.Tutorials.Events; using Samples.Tutorials.Events;
using Samples.Tutorials.MvvmSample;
using Samples.Tutorials.Popups; using Samples.Tutorials.Popups;
using Samples.Tutorials.ToolTips; using Samples.Tutorials.ToolTips;
@@ -80,6 +81,11 @@ namespace Samples
{ {
ShowDialog(new DataBoundToolTipWindow()); ShowDialog(new DataBoundToolTipWindow());
} }
private void btnMvvm_Click(object sender, System.Windows.RoutedEventArgs e)
{
ShowDialog(new MvvmSampleWindow());
}
private void btnMainSample_Click(object sender, RoutedEventArgs e) private void btnMainSample_Click(object sender, RoutedEventArgs e)
{ {

View File

@@ -34,6 +34,7 @@
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile>Client</TargetFrameworkProfile> <TargetFrameworkProfile>Client</TargetFrameworkProfile>
<ExpressionBlendVersion>12.0.41002.1</ExpressionBlendVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@@ -56,6 +57,21 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Tutorials\09 - MVVM\ClockPopup.xaml.cs">
<DependentUpon>ClockPopup.xaml</DependentUpon>
</Compile>
<Compile Include="Tutorials\09 - MVVM\MvvmSampleViewModel.cs" />
<Compile Include="Tutorials\09 - MVVM\MvvmSampleWindow.xaml.cs">
<DependentUpon>MvvmSampleWindow.xaml</DependentUpon>
</Compile>
<Page Include="Tutorials\09 - MVVM\ClockPopup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Tutorials\09 - MVVM\MvvmSampleWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Reference Include="PresentationFramework.Aero" /> <Reference Include="PresentationFramework.Aero" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core"> <Reference Include="System.Core">
@@ -103,6 +119,7 @@
<Compile Include="Showcase\FancyToolTip.xaml.cs"> <Compile Include="Showcase\FancyToolTip.xaml.cs">
<DependentUpon>FancyToolTip.xaml</DependentUpon> <DependentUpon>FancyToolTip.xaml</DependentUpon>
</Compile> </Compile>
<Resource Include="Tutorials\09 - MVVM\Clock.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ApplicationDefinition Include="App.xaml"> <ApplicationDefinition Include="App.xaml">
@@ -325,6 +342,7 @@
<Name>NotifyIconWpf</Name> <Name>NotifyIconWpf</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -0,0 +1,37 @@
<UserControl 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"
mc:Ignorable="d"
x:Class="Samples.Tutorials.MvvmSample.ClockPopup"
x:Name="UserControl"
Height="141"
Width="304">
<UserControl.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#FFA8A8A8"
Offset="0" />
<GradientStop Color="White"
Offset="1" />
</LinearGradientBrush>
</UserControl.Background>
<Grid x:Name="LayoutRoot">
<Rectangle Stroke="#FF727272"/>
<Image Source="Clock.png"
Stretch="Fill"
Height="128"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Width="128"
Margin="10,10,0,0" />
<TextBlock HorizontalAlignment="Left"
Margin="143,0,0,0"
TextWrapping="Wrap"
Text="{Binding Timestamp}"
VerticalAlignment="Center"
FontSize="40"
Foreground="#F2346172" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,15 @@
using System.Windows.Controls;
namespace Samples.Tutorials.MvvmSample
{
/// <summary>
/// Interaction logic for ClockPopup.xaml
/// </summary>
public partial class ClockPopup : UserControl
{
public ClockPopup()
{
this.InitializeComponent();
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;
namespace Samples.Tutorials.MvvmSample
{
public class MvvmSampleViewModel : INotifyPropertyChanged
{
private DispatcherTimer timer;
public string Timestamp
{
get { return DateTime.Now.ToLongTimeString(); }
}
public MvvmSampleViewModel()
{
timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, OnTimerTick, Application.Current.Dispatcher);
}
private void OnTimerTick(object sender, EventArgs e)
{
//fire a property change event for the timestamp
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("Timestamp")));
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,37 @@
<Window x:Class="Samples.Tutorials.MvvmSample.MvvmSampleWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Samples.Tutorials.MvvmSample"
xmlns:tb="http://www.hardcodet.net/taskbar"
Title="MvvmSampleWindow"
Height="300"
Width="300">
<Window.DataContext>
<local:MvvmSampleViewModel />
</Window.DataContext>
<Grid>
<!--
the NotifyIcon automatically derives the DataContext of it's
declaring view. Alternatively, you could just assign it manually
-->
<tb:TaskbarIcon IconSource="/Icons/Inactive.ico"
ToolTipText="{Binding Timestamp}">
<tb:TaskbarIcon.TrayPopup >
<!-- the popup, here a custom user control, will also get the DataContext of the NotifyIcon -->
<local:ClockPopup Opacity="0.8" />
</tb:TaskbarIcon.TrayPopup>
</tb:TaskbarIcon>
<TextBlock TextWrapping="Wrap"
Text="MVVM is quite simple - content of the NotifyIcon derive its DataContext. Sample: Hover over the icon in order to see the bound ToolTipText. Click for a richer Popup that is bound to the same property."
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="10,10,10,0" />
</Grid>
</Window>

View File

@@ -0,0 +1,15 @@
using System.Windows;
namespace Samples.Tutorials.MvvmSample
{
/// <summary>
/// Interaction logic for MvvmSampleWindow.xaml
/// </summary>
public partial class MvvmSampleWindow : Window
{
public MvvmSampleWindow()
{
InitializeComponent();
}
}
}