【发布时间】:2014-06-13 20:15:34
【问题描述】:
我有一个 ItemsControl,里面有很多 Expander,里面有一个 TextBox。
TextBox 有很长的 Text,但它的文本没有换行,而是我在 ItemsControl 上看到了一个我不想要的水平滚动条。我想要文本框上的水平滚动条。我不想要的事件,而是 Textobx 中的文本应该始终环绕并具有垂直滚动条。
我该怎么做?
<Window x:Class="ExpanderTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="768" Width="1024">
<Window.Resources>
<DataTemplate x:Key="NormalTemplate">
<Expander Margin="0" Header="{Binding FileName}" Background="Green">
<TextBox TextWrapping="Wrap" AcceptsReturn="True" IsReadOnly="True" Text="{Binding Content}" Margin="0"/>
</Expander>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding ErrorLogs}" HorizontalContentAlignment="Stretch" ItemTemplate="{DynamicResource NormalTemplate}" />
</Grid>
</Window>
public class MainViewModel : BaseViewModel
{
public MainViewModel()
{
GetErrorLogs();
}
private void GetErrorLogs()
{
for (int i = 0; i < 30; i++)
{
string content = new string('0', 500 * i + 1);
var e = new ErrorLogViewModel { Content = content, FileName = "ErrorLog " + i };
ErrorLogs.Add(e);
}
}
private ObservableCollection<ErrorLogViewModel> _errorLogs = new ObservableCollection<ErrorLogViewModel>();
public ObservableCollection<ErrorLogViewModel> ErrorLogs
{
get { return _errorLogs; }
set
{
_errorLogs = value;
this.RaisePropertyChanged("ErrorLogs");
}
}
}
【问题讨论】: