在我的XAML中,我聲明瞭一個名爲DataConnection的類的實例,該實例名爲MyConnection。從C#訪問XAML實例化對象#
<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>
XAML部件中的所有內容都能正常工作。我想要的是能夠從我的C#代碼中引用MyConnection的實例。
這怎麼可能?