我有一个必须调整其StackPanel容器大小的路径.
<StackPanel x:Name="TrackSurface">
<Path Fill="AliceBlue"
Stroke="Black" StrokeThickness="1"
Data="{StaticResource TranslateZ}">
</Path>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
我考虑使用绑定到容器的转换,但实际上不知道如何.有人可以给我一些暗示吗?
我正在尝试使用开始时的加速和结束时的减速(缓出/缓和)来编写一个从0到x(一维中物体的位置)的插值方法,其中只有总时间的限制提供了加速和减速的持续时间.运动应该复制惯性效应,我正在考虑非线性部分的Hermite曲线.
double Interpolate(
double timeToAccel, double timeCruising, double timeToDecel,
double finalPosition,
double currentTime)
{
//...
}
Run Code Online (Sandbox Code Playgroud)
有人能指出我做的那部分代码吗?我不知道如何整合Hermite曲线,因此不知道我将在加速部分或减速部分移动多少,反过来我无法弄清楚线性速度是多少一部分.
谢谢.
一些参考来说明我的问题.
编辑:
编辑:Roman和Bob10提供了完整的工作解决方案.我实现了罗马的代码.谢谢你们两个,伙计们!我感谢您的完美支持和详细的解决方案,为您节省了长时间的搜索和试用.
我无法弄清楚如何在其一个单元格中使用用户控件正确管理网格列的宽度.我有一个窗口的xaml:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Content="Button" Width="100" HorizontalAlignment="Left"/>
<TextBox Grid.Row="1" />
<local:UserControl1 Grid.Row="2"
HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
并且用户控件是根据需要拉伸的绘图集:
<UserControl x:Class="WpfApplication1.UserControl1"
Height="auto" Width="auto">
<Grid Background="Aqua">
<Path Fill="Coral" Stroke="Black" StrokeThickness="1"
Stretch="Uniform"
HorizontalAlignment="Left" VerticalAlignment="Top">
<Path.Data>
<RectangleGeometry Rect="40,20, 140,30" RadiusX="10" RadiusY="10" />
</Path.Data>
</Path>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
为了帮助我将用户控件背景设置为蓝色.
我希望列的宽度忽略用户控件的"自然"大小.我的意思是我希望用户控件在列布局期间不确定宽度,而是将其宽度调整为列的宽度.
在该示例中,最初Grid将列宽设置为按钮的值,用户控件将使用列宽来调整自身大小.然后,如果在文本框中输入长文本,只要文本框开始比按钮宽,并且列也开始调整大小,反过来用户控件将调整为保持与列相同的大小.
我尝试过拉伸值的组合,并且还在用户控件中使用了MeasureOverride().后者不起作用,因为收到的AvalaibleSize是Infinity,而不是列宽.