2010-10-21 87 views
0

改變DataTemplate中我已經ListBox和DataTemplate的如何通過代碼

我需要設置分組框中Heigth = 300

怎麼辦呢?

<DataTemplate x:Key="data_template"> 
    <GroupBox Header="Категория" Width="300" HorizontalAlignment="Stretch" x:Name="GroupBox"> 
    <DockPanel Tag="{Binding id}"> 
     <Button Click="Button_Click" DockPanel.Dock="Top" > 
     <Button.Content> 
      <DockPanel> 
      <TextBlock Text="{Binding title}" TextWrapping="Wrap" DockPanel.Dock="Top" Padding="5" HorizontalAlignment="Center" Foreground="#FFB51414" /> 
      <l:ScrollViewerEx VerticalScrollBarVisibility="Auto" > 
       <TextBlock Text="{Binding description}" DockPanel.Dock="Top" TextWrapping="Wrap" Padding="5" IsHitTestVisible="False" /> 
      </l:ScrollViewerEx> 
      </DockPanel> 
     </Button.Content> 
     </Button> 
    </DockPanel> 
    </GroupBox> 
</DataTemplate> 

回答

0

你想達到什麼目的?您是否希望GroupBox高度在應用程序運行時發生更改,發生某些事件或某些數據已更改?如果是這樣,那麼您可能要查找的是數據觸發器或事件觸發器,您只需將其添加到DataTemplate中。

1

在的情況下,有人試圖解決我剛纔的問題,我這樣做是這樣的:

DataTemplate mycolumnDataTemplate = null; 
var dataTemplateStream = new SomeClass().GetType().Assembly.GetManifestResourceStream("Some.Namespace.SomeReosurceName.xaml"); 
string dataTemplateString = new System.IO.StreamReader(dataTemplateStream).ReadToEnd(); 
dataTemplateString = dataTemplateString.Replace("[0]", browserColumn.ColumnName); 
mycolumnDataTemplate = XamlReader.Load(dataTemplateString) as DataTemplate;