code-snippet-plugin-for-windows-live-writer
It is highly recommend to use this live writer plugin https://plugins.live.com/writer/detail/code-snippet-plugin-for-windows-live-writer to compose code snippet in the msdn blog.
Many thanks Leo (https://lvildosola.blogspot.in/ )’s contribution years ago!
C#:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Security.Cryptography;
using Windows.Storage.Streams;
using Windows.System.Profile;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// “空白页”项模板在 https://go.microsoft.com/fwlink/?LinkId=234238 上有介绍
namespace App2
{
/// <summary>
/// 可用于自身或导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
TestArea.GotFocus += TestArea_GotFocus;
TestArea.LostFocus += TestArea_LostFocus;
TestArea.PointerEntered += TestArea_PointerEntered;
TestArea.PointerPressed += TestArea_PointerPressed;
TestArea.KeyDown += TestArea_KeyDown;
TestArea.PointerReleased += TestArea_PointerReleased;
}
void TestArea_PointerReleased(object sender, PointerRoutedEventArgs e)
{
//尝试在PointerReleased时再次获取焦点,发现不起作用。
Output.Text += "TestArea_PointerReleased ";
e.Handled = true;
TestArea.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
void TestArea_KeyDown(object sender, KeyRoutedEventArgs e)
{
Output.Text += "TestArea_KeyDown ";
}
void TestArea_PointerPressed(object sender, PointerRoutedEventArgs e)
{
TestArea.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
void TestArea_PointerEntered(object sender, PointerRoutedEventArgs e)
{
TestArea.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
void TestArea_LostFocus(object sender, RoutedEventArgs e)
{
Output.Text += "TestArea_LostFocus ";
}
void TestArea_GotFocus(object sender, RoutedEventArgs e)
{
Output.Text += "TestArea_GotFocus ";
}
/// <summary>
/// 在此页将要在 Frame 中显示时进行调用。
/// </summary>
/// <param name="e">描述如何访问此页的事件数据。Parameter
/// 属性通常用于配置页。</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
}
}
xaml / html:
<Page
x:Class="App2.MainPage"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"></RowDefinition>
<RowDefinition Height="0.8*"></RowDefinition>
</Grid.RowDefinitions>
<local:CustomControl1 x:Name="TestArea" Grid.Row="1" Height="Auto" Width="Auto" Background="Red">
</local:CustomControl1>
<TextBox x:Name="Output" HorizontalAlignment="Left" Margin="10,10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Height="594" Width="370"/>
</Grid>
</Page>
c++
void SDKSample::ThreadPool::PeriodicTimerScenario::CreatePeriodicTimer(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
auto timerDelegate = [this](Windows::System::Threading::ThreadPoolTimer^ timer)
{
auto uiDelegate = [this]()
{
SDKSample::ThreadPool::PeriodicTimerCount++;
SDKSample::ThreadPool::PeriodicScenario->UpdateUI(Status::Completed);
};
Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal,
ref new Windows::UI::Core::DispatchedHandler(uiDelegate));
};
auto time = safe_cast<Platform::String^>(PeriodMs->SelectionBoxItem);
PeriodicTimerMilliseconds = _wtol(time->Data());
Windows::Foundation::TimeSpan Period = ThreadPoolSample::MillisecondsToTimeSpan(PeriodicTimerMilliseconds);
UpdateUI(Status::Started);
PeriodicTimer = Windows::System::Threading::ThreadPoolTimer::CreatePeriodicTimer(ref new Windows::System::Threading::TimerElapsedHandler(timerDelegate), Period);
}
CSS:
body {
font-family: "Segoe UI", Tahoma, Verdana, Arial;
background: #FCFCFC url("../img/header-bar-bg.jpg") repeat-x center top;
color: #2A2A2A;
direction: ltr;
font-size: 83%;
margin: 0;
}
img {
border: 0px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #333333;
font-weight: normal;
line-height: normal;
margin: 0;
}
JavaScript:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
Comments
Anonymous
January 25, 2015
The plug-in location does not exist any longer, seems like. :(Anonymous
March 15, 2015
You don't happen to have the installer somewhere, do you?Anonymous
August 27, 2015
I think it's the same as this one on codeplex wlwplugincollection.codeplex.com/.../9392