I am working on the GUI of an application that a coworker and I are working on. There is a GUI bug that has been bugging me and I haven't been able to figure out how to fix.
我正在研究一个同事和我正在研究的应用程序的GUI。有一个GUI错误一直困扰着我,我无法弄清楚如何修复。
In my GUI there is a gridrow. In one of the columns is a down arrow image that I can press. When you click on the arrow, it will expand additional information. I used the RowDetailsTemplate for the additional information. When you click it again, the additional information will go away. I used a Mouse_Down event to change the visibility of the rows detail from visible to collapsed and vice versa to do this.
在我的GUI中有一个gridrow。其中一列是我可以按下的向下箭头图像。当您单击箭头时,它将展开其他信息。我使用RowDetailsTemplate获取其他信息。当您再次单击它时,附加信息将消失。我使用Mouse_Down事件将行详细信息的可见性从可见更改为折叠,反之亦然,以执行此操作。
The problem is, after I collapsed the additional information, the size of the grid is still expanded as though to fit the additional information. But the additional information's visibility is already set to collapsed so why is my grid not changing back to the original height? How can I resize the height of the datagridrow to the size of its children?
问题是,在我折叠了附加信息之后,网格的大小仍然被扩展,好像是为了适应附加信息。但附加信息的可见性已经设置为折叠,为什么我的网格没有变回原来的高度?如何将datagridrow的高度调整为其子项的大小?
EDIT:
This is my gridrow which originally sets the rowdetails to collapsed:
这是我的gridrow,它最初将rowdetails设置为折叠:
<DataGrid Grid.Row="1" ItemsSource="{Binding ReadUnits}" BorderThickness="0" Name="dataGrid" RowDetailsVisibilityMode="Collapsed" HeadersVisibility="Column" GridLinesVisibility="Horizontal" VerticalScrollBarVisibility="Disabled" >
This is the code where the image to click is. The row is inherting this data template. This is were I can creating the Mouse Down event.
这是要单击的图像的代码。该行正在包含此数据模板。这是我可以创建Mouse Down事件。
<DataGridTemplateColumn Header="" Width="30">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="navigationImage" Source=".../expand.png" Width="16" Height="16" MouseDown="navigationImage_MouseDown" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
This is where the event is. This will set the visibility of the rowdetails.
这是活动的地方。这将设置rowdetails的可见性。
private void navigationImage_MouseDown(object sender, MouseButtonEventArgs e)
{
FrameworkElement frameworkElement = (FrameworkElement)sender;
Image image = (Image)sender;
DataGridRow dataGridRow = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(frameworkElement.DataContext);
if (dataGridRow.DetailsVisibility == Visibility.Collapsed)
{
dataGridRow.DetailsVisibility = Visibility.Visible;
BitmapImage icon = new BitmapImage(new Uri(".../collapse.png"));
image.Source = icon;
}
else
{
dataGridRow.DetailsVisibility = Visibility.Collapsed;
BitmapImage icon = new BitmapImage(new Uri(".../expand.png"));
image.Source = icon;
}
}
2 个解决方案
#1
0
It depends on the rowheight and rows you created to host the grid which has "additional information". in your row definition try giving height as "Auto"..
它取决于您创建的行高和行以托管具有“附加信息”的网格。在你的行定义中尝试将高度设为“自动”..
Something like this..
像这样的东西......
<RowDefinition Height="Auto"></RowDefinition>
#2
0
So after trying to fix my problem through brute force and using code that looks less than optimal I decided to try and search the web some more and came upon this answer which fixed my problem: http://social.msdn.microsoft.com/Forums/da-DK/wpf/thread/a0e7aea8-e9ad-441f-a775-1178aab75fb0
因此,在尝试通过蛮力修复我的问题并使用看起来不太理想的代码后,我决定尝试搜索更多的网页并找到解决问题的答案:http://social.msdn.microsoft.com/论坛/ DA-DK / WPF /线程/ a0e7aea8-e9ad-441f-a775-1178aab75fb0
I seemed to have resolved the issue by setting a completely unrelated setting.
我似乎通过设置一个完全不相关的设置解决了这个问题。
In my child grids I had ScrollViewer.CanContentScroll set to True. Once I set it to False in all the Child Grids it seemed to magically work. Now when I collapse my row details it resizes the containing row appropriately. The one thing that I'd like to see if you can help me with is determining is explain how this fixed the issue.
在我的子网格中,我将ScrollViewer.CanContentScroll设置为True。一旦我在所有儿童网格中将其设置为假,它似乎神奇地工作。现在当我折叠我的行细节时,它会适当地调整包含行的大小。如果你可以帮助我,我想看到的一件事是确定解释这是如何解决问题的。
What I believe happened is when I expanded the dropdown, the scrollviewer was doing its thing but the scrollviewer was just invisible but still there and expanding the parent grid as the child grew bigger. With the scrollviewer disabled, the issues disappeared.
我相信发生的事情是当我扩展下拉列表时,滚动查看器正在做它的事情但滚动查看器只是看不见但仍然存在并随着孩子变大而扩展父网格。滚动查看器禁用后,问题就消失了。
#1
0
It depends on the rowheight and rows you created to host the grid which has "additional information". in your row definition try giving height as "Auto"..
它取决于您创建的行高和行以托管具有“附加信息”的网格。在你的行定义中尝试将高度设为“自动”..
Something like this..
像这样的东西......
<RowDefinition Height="Auto"></RowDefinition>
#2
0
So after trying to fix my problem through brute force and using code that looks less than optimal I decided to try and search the web some more and came upon this answer which fixed my problem: http://social.msdn.microsoft.com/Forums/da-DK/wpf/thread/a0e7aea8-e9ad-441f-a775-1178aab75fb0
因此,在尝试通过蛮力修复我的问题并使用看起来不太理想的代码后,我决定尝试搜索更多的网页并找到解决问题的答案:http://social.msdn.microsoft.com/论坛/ DA-DK / WPF /线程/ a0e7aea8-e9ad-441f-a775-1178aab75fb0
I seemed to have resolved the issue by setting a completely unrelated setting.
我似乎通过设置一个完全不相关的设置解决了这个问题。
In my child grids I had ScrollViewer.CanContentScroll set to True. Once I set it to False in all the Child Grids it seemed to magically work. Now when I collapse my row details it resizes the containing row appropriately. The one thing that I'd like to see if you can help me with is determining is explain how this fixed the issue.
在我的子网格中,我将ScrollViewer.CanContentScroll设置为True。一旦我在所有儿童网格中将其设置为假,它似乎神奇地工作。现在当我折叠我的行细节时,它会适当地调整包含行的大小。如果你可以帮助我,我想看到的一件事是确定解释这是如何解决问题的。
What I believe happened is when I expanded the dropdown, the scrollviewer was doing its thing but the scrollviewer was just invisible but still there and expanding the parent grid as the child grew bigger. With the scrollviewer disabled, the issues disappeared.
我相信发生的事情是当我扩展下拉列表时,滚动查看器正在做它的事情但滚动查看器只是看不见但仍然存在并随着孩子变大而扩展父网格。滚动查看器禁用后,问题就消失了。