Skip to content

Instantly share code, notes, and snippets.

@Myoga1012
Last active January 30, 2023 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Myoga1012/b5cf2db272e585560535 to your computer and use it in GitHub Desktop.
Save Myoga1012/b5cf2db272e585560535 to your computer and use it in GitHub Desktop.
XAMLでカレンダーを出力するコードです。ロジック用コードは初期化のみです。
// ロジック用コードです。主役はXAMLのコードだよ。
using System.Windows;
namespace WPF {
public partial class MainWindow : Window {
public MainWindow() { InitializeComponent(); }
}
}
<!--
名前 : Myoga Screw-bright (旧名:Myoga S. Tomonaka)
Twitter : https://twitter.com/Myoga1012
-->
<Window x:Class="WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding DisplayDate, ElementName=cal, StringFormat=\{0:d\}, ConverterCulture=ja-jp}"
Height="207" Width="200" ResizeMode="NoResize">
<Calendar x:Name="cal"/>
</Window>
<!--
Calender.xaml
Copyright (c) 2014 Myoga-TN.net All Rights Reserved.
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
-->
@Myoga1012
Copy link
Author

Calendar.DisplayDateとのデータバインディング時、StringFormatを「{0:d}」と指定すると、値が「MM/DD/YYYY」という文字列になります。さらにConverterCultureをデフォルトの「en-us」から
「ja-jp」にすると、「YYYY/MM/DD」という表現になります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment