0
對於XAML TextBlock中,你可以做以下的一個DataTemplate內:DataGridTemplateColumn是否存在TextBlock ScrollViewer.CanContentScroll =「True」的代碼隱藏等價物?
<TextBlock Text="myTextBlock Text" VerticalAlignment="Center" Margin="0,0,5,0"
ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
但是,當我嘗試設置ScrollViewer.HorizonalScrollBarVisibility,它似乎並沒有做任何事情。
DataTemplate textBlockTemplate = new DataTemplate();
FrameworkElementFactory textBlockElement = new FrameworkElementFactory(typeof(TextBlock));
Binding c1Binding = new Binding("myBindingValue") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged };
textBlockElement.SetBinding(TextBlock.TextProperty, c1Binding);
textBlockElement.SetValue(TextBlock.TextWrappingProperty, TextWrapping.Wrap);
textBlockElement.SetValue(TextBlock.HeightProperty, System.Convert.ToDouble(23));
textBlockElement.SetValue(ScrollViewer.CanContentScrollProperty, true);
textBlockElement.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Visible);
textBlockTemplate.VisualTree = textBlockElement;
templateColumn.CellTemplate = textBlockTemplate;
myDataGrid.Columns.Add(templateColumn);
我試圖讓有一個TextBlock顯示一行文字DataGrid列,但可以讓你向上/向下滾動看到文本塊的其餘部分。