【发布时间】:2011-10-17 11:32:14
【问题描述】:
我的问题和这个类似;
除非我希望行详细信息永远不会超过它所跨越的列的宽度。
|--0--|--1--|--2--|--3--|--4--|
|---------Row-Details---------|
我试过AreRowDetailsFrozen,但没有效果。我也尝试绑定到父网格的实际宽度(OneWay),但这会导致宽度超过我的两个屏幕的宽度。
这是我目前的尝试(简化);
<Grid>
<DataGrid x:Name="Grid"
Grid.Row="1"
ItemsSource="{Binding Collection}"
IsReadOnly="True"
AutoGenerateColumns="False"
ColumnWidth="Auto"
CanUserResizeColumns="False"
CanUserResizeRows="False"
RowDetailsVisibilityMode="VisibleWhenSelected"
AreRowDetailsFrozen="True"
SelectionUnit="FullRow"
VerticalAlignment="Top"
HorizontalAlignment="Center">
<DataGrid.RowDetailsTemplate>
<!-- Begin row details section. -->
<DataTemplate>
<TextBox DataContext="{Binding ErrorMessage}"
IsReadOnly="True"
Margin="5"
BorderBrush="Transparent"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True"
TextWrapping="Wrap"
Text="{Binding .}">
</TextBox>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
这会导致以下结果;
|--0--|--1--|--2--|--3--|--4--|
|---------Row-Details are as wide as the longest row in their content ---------|
将 TextBox 的宽度绑定到任何父容器(Grid、DataGrid、ItemsPresenter):
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth, Mode=OneWay}"
结果:
|------Viewable Area-------|
|---- Columns ----|
|---------Row-Details --------------------------------------------------------------|
很郁闷,我只是想让Row Details不要改变DataGrid的宽度,有这么多要求吗? :)
【问题讨论】:
标签: c# wpf width rowdetailstemplate