2016-12-11 1 views
0

이 간단한 솔루션이 있어야하지만 찾을 수 없습니다. 데이터가 포함 된 DataGridTextColumns가있는 DataGrid가 있습니다. 이것은 잘 작동합니다. 난 그냥 셀 안의 String을 줄 바꿈으로 만들지 않는 대신, 모든 것이 한 줄에있다. (문자열의 길이에 관계없이).C# DataGridTextColumn 줄 바꿈

dataGrid.IsReadOnly = true; 
dataGrid.AutoGenerateColumns = false; 
dataGrid.ItemsSource = ConvertListIntoPlantViewModel(lList); 

DataGridTextColumn textColumn1 = new DataGridTextColumn(); 
DataGridTextColumn textColumn2 = new DataGridTextColumn(); 
DataGridTextColumn textColumn3 = new DataGridTextColumn(); 
textColumn3.MaxWidth = 200; 

textColumn1.Header = "Name"; 
textColumn1.Binding = new Binding("Name"); 
textColumn2.Header = "Type"; 
textColumn2.Binding = new Binding("Type"); 
textColumn3.Header = "Info"; 
textColumn3.Binding = new Binding("Information"); 

dataGrid.Columns.Add(textColumn1); 
dataGrid.Columns.Add(textColumn2); 
dataGrid.Columns.Add(textColumn3); 

의 내가 (폭 200) 셀의 끝에서 줄 바꿈을 할 textColumn3에서 끝나는 텍스트를 만들고 싶어한다고 가정 해 봅시다. 이것을 어떻게 성취합니까? 설정할 수있는 간단한 스타일 요소가 있어야합니다. 맞습니까? 나는 그것을 찾을 수 없다.

감사합니다. 감사합니다.

답변

1

설정할 수있는 간단한 스타일 요소가 있어야합니다. 맞습니까? 나는 그것을 찾을 수 없다.

예, 포장 텍스트에 다음과 같은 스타일의 열 (들)의 ElementStyle 속성을 설정할 수 있습니다 :

<Style TargetType="TextBlock"> 
    <Setter Property="TextWrapping" Value="Wrap" /> 
</Style> 

당신은 프로그래밍 XamlReader.Parse 방법을 사용하여 스타일을 만들 수 있습니다 :

string xaml = "<Style xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" TargetType=\"TextBlock\"><Setter Property=\"TextWrapping\" Value=\"Wrap\"/></Style>"; 
Style style = System.Windows.Markup.XamlReader.Parse(xaml) as Style; 

DataGridTextColumn textColumn1 = new DataGridTextColumn(); 
textColumn1.ElementStyle = style; 
+0

덕분에 프로그래밍 방식을 선호합니다. 그것은 완벽하게 작동합니다! :) 타이 – Vitriol