0

XAML の TextBlock の場合、DataTemplate 内で次の操作を実行できます。

<TextBlock Text="myTextBlock Text" VerticalAlignment="Center" Margin="0,0,5,0" 
ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Visible"/>

しかし、ScrollViewer.Horizo​​nalScrollBarVisibility を設定しようとすると、何もしないようです。

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);

1行のテキストを表示するTextBlockを持つDataGrid列を作成しようとしていますが、上下にスクロールして残りのテキストブロックを表示できます。

4

1 に答える 1

0

TextBlockScrollViewerスクロール動作をオンに設定するための が含まれていません。必要なScrollViewerものを設定できる でラップする必要があります。これを a と対比してください。a にListBoxは a が含まScrollViewerれているControlTemplateため、添付されたプロパティを利用できます。

于 2013-05-09T15:34:47.283 に答える