2010-06-25 155 views

回答

6
<Window.Resources> 
    <DataTemplate x:Key="PersonDataTemplate"> 
    <StackPanel Orientation="Horizontal"> 
     <TextBlock Text="{Binding Path=Name}" /> 
     <TextBlock Text="{Binding Path=Age}" /> 
    </StackPanel> 
    </DataTemplate> 
</Window.Resources> 

public Window1() 
{ 
    InitializeComponent(); 

    DataTemplate dataTemplate = FindResource("PersonDataTemplate") as DataTemplate; 
} 
+2

但是如何找到DataTemplate中的控件,即TextBlock,並在運行時從代碼隱藏中更改該值?請幫忙...! – 2013-05-24 06:42:33

+0

謝謝!正在尋找這個:D – 2017-07-18 15:25:36

相關問題