WPF XAML TextBox控件绑定当前日期方法

  1. XAML文件引入System命名空间
<UserControl x:Class="UI.UCInformation"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:local="clr-namespace:UI"
             mc:Ignorable="d" 
             d:DesignHeight="240" d:DesignWidth="400">

UserControl>
  1. 增加TextBox控件并绑定Now属性
<Grid Margin="10 25 10 10">
        
Grid>

3 绑定后效果
WPF XAML TextBox控件绑定当前日期方法_第1张图片

  1. 完整XAML代码
<UserControl x:Class="UI.UCInformation"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:local="clr-namespace:UI"
             mc:Ignorable="d" 
             xmlns:SAUtil="clr-namespace:SAUtilLib;assembly=SAUtilLib"
             d:DesignHeight="240" d:DesignWidth="400">
    <UserControl.Resources>
        <sys:DateTime x:Key="DataTimeDataSource" d:IsDataSource="True"/>
    UserControl.Resources>
    <Grid Margin="10 25 10 10" DataContext="{x:Static local:SysCfg.Default}">
    	 
    Grid>
UserControl>

你可能感兴趣的:(WPF,wpf)