- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个 3 列 UI,列之间有网格拆分器。我需要保存列的状态,这样如果用户关闭并重新打开应用程序,它看起来就像他们离开它一样。但我也试图让列按比例拆分——我的意思是,如果你拉伸(stretch)窗口,所有三个面板都会增长,如果你移动左拆分器,它会改变左列和中间列之间的划分。
我目前只实现了第一个要求 - 它保存了列宽的状态。我还让列强制所有三列的最小宽度。但据我了解,告诉拆分器按比例拆分的方法是使用星号大小的列宽。因为我已经在使用 Width 属性来保存和恢复状态,所以我不确定我能否完成我想要的。
有没有人设法保存列宽的状态并让拆分成比例?
这是我目前所拥有的一些代码:
<Grid x:Name="mainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="leftColumn" Width="{Binding MainWindowLeftColumnWidth, Mode=TwoWay, Source={x:Static prop:Settings.Default}}" MinWidth="200" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}, Path=LeftColumnMaxWidth, Mode=OneWay}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition x:Name="centerColumn" Width="{Binding MainWindowCenterColumnWidth, Mode=TwoWay, Source={x:Static prop:Settings.Default}}" MinWidth="300" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}, Path=CenterColumnMaxWidth, Mode=OneWay}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition x:Name="rightColumn" Width="*" MinWidth="500"/>
</Grid.ColumnDefinitions>
<StackPanel x:Name="leftPanel" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
<GridSplitter x:Name="leftSplitter" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="5" ResizeDirection="Columns"/>
<StackPanel x:Name="centerPanel" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
<GridSplitter x:Name="rightSplitter" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="5" ResizeDirection="Columns"/>
<StackPanel x:Name="rightPanel" Grid.Column="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" SizeChanged="rightPanel_SizeChanged"/>
</Grid>
private void CalculateMaxWidths()
{
FrameworkElement content = Content as FrameworkElement;
if (content != null)
{
LeftColumnMaxWidth = content.ActualWidth
- leftSplitter.ActualWidth
- centerColumn.ActualWidth
- rightSplitter.ActualWidth
- rightColumn.MinWidth;
CenterColumnMaxWidth = content.ActualWidth
- leftColumn.ActualWidth
- leftSplitter.ActualWidth
- rightSplitter.ActualWidth
- rightColumn.MinWidth;
}
}
最佳答案
所以我相信我已经想通了。我的 settings.settings 中的一些旧值可能会导致我出现问题,并且我输入的默认值可能会导致我出现问题。但这就是我所做的:
<Grid x:Name="mainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="leftColumn" MinWidth="200" Width="200*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition x:Name="centerColumn" MinWidth="300" Width="300*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition x:Name="rightColumn" MinWidth="498" Width="498*"/>
</Grid.ColumnDefinitions>
<StackPanel x:Name="leftPanel" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
<GridSplitter x:Name="leftSplitter" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="5" ResizeDirection="Columns"/>
<StackPanel x:Name="centerPanel" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
<GridSplitter x:Name="rightSplitter" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="5" ResizeDirection="Columns"/>
<StackPanel x:Name="rightPanel" Grid.Column="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" SizeChanged="rightPanel_SizeChanged"/>
</Grid>
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
//...
try
{
GridLengthConverter converter = new GridLengthConverter();
leftColumn.Width = (GridLength)converter.ConvertFromString(Settings.Default.MainWindowLeftColumnWidth);
centerColumn.Width = (GridLength)converter.ConvertFromString(Settings.Default.MainWindowCenterColumnWidth);
rightColumn.Width = (GridLength)converter.ConvertFromString(Settings.Default.MainWindowRightColumnWidth);
Trace.WriteLine(string.Format("LOADED Left: {0}, Center: {1}, Right {2}", leftColumn.Width, centerColumn.Width, rightColumn.Width));
}
catch (Exception)
{
// Fail silently, the worse case is we go with the defaults, it's going to be okay
}
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
//...
try
{
GridLengthConverter converter = new GridLengthConverter();
Settings.Default.MainWindowLeftColumnWidth = converter.ConvertToString(leftColumn.Width);
Settings.Default.MainWindowCenterColumnWidth = converter.ConvertToString(centerColumn.Width);
Settings.Default.MainWindowRightColumnWidth = converter.ConvertToString(rightColumn.Width);
Trace.WriteLine(string.Format("SAVED Left: {0}, Center: {1}, Right {2}", Settings.Default.MainWindowLeftColumnWidth, Settings.Default.MainWindowCenterColumnWidth, Settings.Default.MainWindowRightColumnWidth));
}
catch (Exception)
{
// Fail silently, the worst case is we don't save a little something, it's going to be okay
}
}
private void PanelSizeChanged(object sender, SizeChangedEventArgs e)
{
// In order to keep the resizing from losing proportionality, we'll force it to be proportional to the current size.
// Otherwise the right panel edges up and up while the other two remain at their starting 200*/300* values.
// And when that happens eventually resizing the window only resizes the right panel, not proportionately as it does at the start.
leftColumn.Width = new GridLength(leftColumn.ActualWidth, GridUnitType.Star);
centerColumn.Width = new GridLength(centerColumn.ActualWidth, GridUnitType.Star);
rightColumn.Width = new GridLength(rightColumn.ActualWidth, GridUnitType.Star);
}
关于WPF GridSplitter - 保存和恢复位置并按比例拆分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5018544/
所以基本上我有一个导航栏,我只想有一定的宽度。它有 4 个元素,我希望它正好是这些元素的宽度。这是它在我的工作计算机上的样子。 这正是我想要的样子。导航栏在最后一个元素的末尾完美结束,并且居中。我自己
如何将多个过滤器链接到一个视频中? 基本上 - 我有一个叠加图像(透明 gif),想要将它居中,并为 gif 应用 30% 的不透明度。这就是我所拥有的: ffmpeg -i inputmovie.m
我正在使用此命令对视频进行编码 $transcode = FFMPEG_BINARY.' -loglevel panic -y -i "'.$files['original'].'" -vf scal
我正在使用 Laravel 网站,包括 照片滑动 . 这是我的问题:当我单击照片时,它会以预定义的高度和宽度(在我的情况下为 764X480)弹出。我希望我的照片以原始比例打开,而不是预定义的(因为我
假设我想计算每个组中不同值的比例。例如,使用 mtcars 数据,如何计算 am 的齿轮数量的相对频率(自动/手动)用 dplyr 一次性完成? library(dplyr) data(mtcars)
我用一个非常小的标记散点图数据点(见下面的屏幕截图)。当我使用非常小的标记 ',' 时,图例很难阅读(示例代码取自 here )。 (Python 3,Jupyter 实验室) 如何增加图例中标记的大
我有这个数据框: o d r kz p 1 3 1 5 NaN 1 3 2 0 NaN 1 10 1 7 NaN 1 10 3 1
我对 R 很陌生,所以如果我的问题中有不清楚的地方,请耐心等待。 我有一个 data.frame “蛋白质”有5列,即; 1.protein_name, 2.protein_FC, 3.protein
我有一个带有 webgl 的 Canvas 。我初始化 webgl,创建一个片段和一个顶点着色器、两个覆盖整体的三 Angular 形和一个纹理。 const vertexShaderSource =
我想找到包括旋转,比例和位置的匹配模板。但是cvMatchTemplate没有提供这些详细信息,它仅检测位置。 我看过使用棋盘的例子。但是我想用自定义图像实现相同的示例。 感谢帮助。 问候 最佳答案
我正在尝试制作像欧洲体育应用程序中那样的侧边栏菜单!当菜单从左侧滑动时,sourceviewcontroller 向左滑动并变小。 var percentWidthOfContainer = cont
https://stackblitz.com/edit/js-meta-viewport 在 Chrome 调试器中,当我点击“可以缩放”但无法在移动设备 (Nexus 5 (Chrome 70))
针对一台设备进行优化后, ImageView 会按照布局中定义的正确比例显示。然而,如何才能更进一步,使各种 ImageView 在不同设备上缩放? android:layout_width="fil
我正在尝试创建一个具有两个 View 的 View Controller ,其中一个实际上是自定义 TableView ,如下所示: 是否可以添加某种比例约束,以便在所有设备和所有方向上,上 View
我正在使用 PhoneGap 为 Android 开发。下面你可以看到我的代码,我不能做的是在用户更改比例后将 WebView 比例重置为 1。 The reset code should be im
我有一个涉及大量图像的元素。 问题是每个图像都有不同的分辨率(高度/宽度)。它从 200x600 之类的小图像变成了 3000x5000 大声笑。 我正在尝试找到一种方法将所有图像的大小减小到 (MA
我想在运行时设置视口(viewport)比例 - 移动浏览器是否应该在设置后立即应用更改?这就是我正在尝试的: var scale = 2.0; var viewport = document.get
我在 paperjs 中有一个圆形和一个矩形对象。现在我想制作动画。在该动画中,圆圈上升并且矩形必须在圆圈之后(在圆圈底部)增长。我在这里有一个例子(不是我想要的那样工作) example 代码: v
对不起,我不能给标题带来完美的含义。您可以在 http://dainielhhong.com/page1.html 测试代码 无论屏幕大小如何,我都想使 crack 和 box fit。 它适合我的显
我是 D3 v3 的新手,正在学习一些有关基本线性和序数尺度的教程。我正在修改教程中的一段代码。我想让颜色根据窗口的大小显示和缩放。如果有更多数据,那么它应该再次均匀分布以容纳所有数据。 var da
我是一名优秀的程序员,十分优秀!