我有一个TextBlock控件,我想绑定当前的系统日期,我怎么能通过Code Behind做到这一点?
目标是在此TecBlock中显示当前的系统日期和时间,并且我不需要一次只控制刷新一次.
我希望这是最简单的Code.I不想创建dateTime属性.以下是我的代码:它找不到BindSource是错的
Binding bd = new Binding("System.DateTime.Now");
bd.Source = this;
textBox.SetBinding(TextBox.TextProperty, bd);
Run Code Online (Sandbox Code Playgroud)
感谢帮助
<Style TargetType="ListBoxItem" x:Key="ListBoxItemTemplate">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Button Content="{TemplateBinding Content}"></Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ListBox ItemsSource="{Binding S}"
x:Name="listBox"
ItemContainerStyle="{StaticResource ListBoxItemTemplate}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid x:Name="grid" Columns="5"></UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我想从ListBox Control中找到"grid".请帮助我,谢谢.