0
我有一個帶有許多擴展器的ItemsControl,裏面有一個TextBox。文本框在擴展器控件內不換行
該文本框有長文本,但其文本不行換行,而是我看到了ItemsControl上的水平滾動條,我不想要。我想要Textbox上的水平滾動條。事件,我不想要而是在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");
}
}
}