【发布时间】:2017-03-26 17:05:23
【问题描述】:
我似乎很难找到我的问题的答案(我已经阅读了很多,但没有一个对我有用)。我正在尝试在位于主窗口的 TextBlock 中显示存储在 MainWindow.xaml.cs 中的一些 DateTime。我正在玩它,所以我设置了一个测试代码:
MainWindow.xaml.cs:
public partial class MainWindow : Window
{
public DateTime displayTime;
public MainWindow()
{
displayTime = new DateTime(1,1,1,0,1,21,306);
InitializeComponent();
}
}
MainWindow.xaml:
<Window x:Class="Project1.MainWindow"
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"
xmlns:local="clr-namespace:Project1"
mc:Ignorable="d"
Title="Main Window" MinHeight="450" Height="450" MinWidth="650" Width="650">
<TextBlock Text="{Binding Path=displayTime, StringFormat='{}{0:h \: m \: ss\.fff}', Mode=OneWay}" />
【问题讨论】:
标签: c# .net wpf xaml data-binding