私はWPFを学んでいます。
WPF アプリケーションの XAML コードを考慮します。
<Window x:Class="_0SE_BridgingCodeBehind.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Window.Resources>
<col:ArrayList x:Key="MyDataSource">
<sys:DateTime>1/2/2003 5:00:00</sys:DateTime>
<sys:DateTime>4/5/2006 13:13:13</sys:DateTime>
<sys:DateTime>7/8/2009 23:59:59</sys:DateTime>
</col:ArrayList>
</Window.Resources>
<Canvas>
<ListBox Width="200" Height="100"
ItemsSource="{StaticResource MyDataSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding DayOfWeek}"
Width="80" Background="Red" />
<Label Content="{Binding DayOfYear}"
Width="50" Background="Yellow" />
<Label Content="{Binding TimeOfDay}"
Background="LightBlue" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Canvas>
</Window>
codepoject の記事「WPF Lists/Views - A Visual Quick Start」(「データ テンプレート」セクション) から
、プロジェクト コードを順番に変更するにはどうすればよいですか。
- 4 番目の 3 つの既存の静的値に追加するには
MyDataSource
、たとえば、4/4/2013 13:12:13
C# コードの値 (MainWindow.xaml.cs
)? - C# コードで 2 番目の DateTime 値を取得するに
4/5/2006 13:13:13
はMyDataSource
(現在は XAML コード内)?
更新: Henk Holterman の回答
に従いました(小さな変更を加えて):
<Canvas>
<ListBox Width="200" Height="100"
x:Name="myListBox"
ItemsSource="{StaticResource MyDataSource}"
私はC#から値をレンダリングしました(XAMLからそれらを失いましたが、私はそれらを望んでいません)またはC#でXAML値をレンダリングしましたが、両方ではありません。