mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-01-14 01:25:45 -05:00
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:
@@ -3,11 +3,11 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="NotifyIcon Samples"
|
||||
Height="563"
|
||||
Height="626"
|
||||
Width="703"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d" ResizeMode="NoResize">
|
||||
<Grid
|
||||
Hyperlink.RequestNavigate="OnNavigationRequest">
|
||||
<Grid.Background>
|
||||
@@ -118,12 +118,11 @@
|
||||
x:Name="btnToolTipControl"
|
||||
Click="btnToolTipControl_Click" />
|
||||
<TextBlock
|
||||
Margin="0,50,328.76,0"
|
||||
Margin="255.31,50,0,0"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold"
|
||||
TextWrapping="Wrap"
|
||||
HorizontalAlignment="Right"
|
||||
d:LayoutOverrides="HorizontalAlignment, Width">
|
||||
HorizontalAlignment="Left" Width="110.93">
|
||||
<Run
|
||||
Text="Showcase Sample:" />
|
||||
</TextBlock>
|
||||
@@ -207,7 +206,7 @@
|
||||
Height="1"
|
||||
Data="M11,517 L561.07363,517" Opacity="0.33" />
|
||||
<Button
|
||||
Margin="11,429,0,0"
|
||||
Margin="10,466,0,0"
|
||||
Content="Events"
|
||||
VerticalAlignment="Top"
|
||||
Height="27"
|
||||
@@ -222,6 +221,15 @@
|
||||
Height="27"
|
||||
x:Name="btnDataBinding"
|
||||
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>
|
||||
</Window>
|
||||
@@ -6,6 +6,7 @@ using Samples.Tutorials.Commands;
|
||||
using Samples.Tutorials.ContextMenus;
|
||||
using Samples.Tutorials.DataBinding;
|
||||
using Samples.Tutorials.Events;
|
||||
using Samples.Tutorials.MvvmSample;
|
||||
using Samples.Tutorials.Popups;
|
||||
using Samples.Tutorials.ToolTips;
|
||||
|
||||
@@ -80,6 +81,11 @@ namespace Samples
|
||||
{
|
||||
ShowDialog(new DataBoundToolTipWindow());
|
||||
}
|
||||
|
||||
private void btnMvvm_Click(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
ShowDialog(new MvvmSampleWindow());
|
||||
}
|
||||
|
||||
private void btnMainSample_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<ExpressionBlendVersion>12.0.41002.1</ExpressionBlendVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -56,6 +57,21 @@
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<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="System" />
|
||||
<Reference Include="System.Core">
|
||||
@@ -103,6 +119,7 @@
|
||||
<Compile Include="Showcase\FancyToolTip.xaml.cs">
|
||||
<DependentUpon>FancyToolTip.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Resource Include="Tutorials\09 - MVVM\Clock.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
@@ -325,6 +342,7 @@
|
||||
<Name>NotifyIconWpf</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- 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.
|
||||
|
||||
BIN
Source/Sample Project/Tutorials/09 - MVVM/Clock.png
Normal file
BIN
Source/Sample Project/Tutorials/09 - MVVM/Clock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
37
Source/Sample Project/Tutorials/09 - MVVM/ClockPopup.xaml
Normal file
37
Source/Sample Project/Tutorials/09 - MVVM/ClockPopup.xaml
Normal 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>
|
||||
15
Source/Sample Project/Tutorials/09 - MVVM/ClockPopup.xaml.cs
Normal file
15
Source/Sample Project/Tutorials/09 - MVVM/ClockPopup.xaml.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user