Trong XAML của tôi, tôi khai báo một cá thể của một lớp có tên là DataConnection, cá thể được đặt tên là MyConnection.Truy cập đối tượng khởi tạo XAML từ C#
<Window.Resources>
<!-- Create an instance of the DataConnection class called MyConnection -->
<!-- The TimeTracker bit comes from the xmlns above -->
<TimeTracker:DataConnection x:Key="MyConnection" />
<!-- Define the method which is invoked to obtain our data -->
<ObjectDataProvider x:Key="Time" ObjectInstance="{StaticResource ResourceKey=MyConnection}" MethodName="GetTimes" />
<ObjectDataProvider x:Key="Clients" ObjectInstance="{StaticResource ResourceKey=MyConnection}" MethodName="GetClients" />
</Window.Resources>
Mọi thứ trong phần XAML đều hoạt động tốt. Những gì tôi muốn là có thể tham chiếu đến trường hợp MyConnection của tôi từ mã C# của tôi.
Làm cách nào có thể?