如何解决将滑块绑定到WPF中XAML中的3D线移动动作
我已经在Windows 7中使用C#构建了WPF 3D项目。 我刚刚创建了2个滑块(垂直和水平)和2条3D线(垂直和水平),想要分别将滑块绑定到3D线移动动作。
XAML:
<UserControl x:Class="STIGenericReport.UserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tool3d="clr-namespace:_3DTools;assembly=3DTools"
Height="407" Width="633" Background="White" BorderBrush="White" Focusable="False">
<Grid Name="maingrid" Background="White" Height="405" Width="616" MinWidth="500">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="619*" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height ="574*" />
<RowDefinition Height="26" MinHeight="16" />
</Grid.RowDefinitions>
<Viewport3D Name="mainViewport" ClipToBounds = "False"
IsHitTestVisible="false"
RenderOptions.EdgeMode="Aliased" Margin="12,52,144,47">
<Viewport3D.Camera>
<OrthographicCamera x:Name="camera" Width="2"
FarPlaneDistance="10"
NearPlaneDistance="1"
LookDirection="0,-1"
UpDirection="0,1,0"
Position="0,2" />
</Viewport3D.Camera>
<Viewport3D.Children>
<ModelVisual3D x:Name="Light1">
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="1,-1" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="Light2">
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="-1,-1" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="Light3">
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="0,-1,-0.5" />
</ModelVisual3D.Content>
</ModelVisual3D>
<tool3d:ScreenSpaceLines3D Points ="0,100,-100,0" Color="Black" Thickness="2"/>
<tool3d:ScreenSpaceLines3D Points ="-100,0" Color="Black" Thickness="2"/>
</Viewport3D.Children>
</Viewport3D>
<Canvas x:Name="canvasOn3D" Background="#00E6FFFF"
Margin="20,102,18"></Canvas>
<Label Content="Trayinfo" FontSize="16" FontWeight="Bold" Height="34" HorizontalAlignment="Left" Margin="192,0" Name="lblTrayinfo" VerticalAlignment="Top" Width="194" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,257" Name="btn9" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,232" Name="btn8" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button HorizontalAlignment="Left" Margin="499,149,207" Name="btn7" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,182" Name="btn6" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,157" Name="btn5" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,132" Name="btn4" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,107" Name="btn3" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,82" Name="btn2" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,57" Name="btn1" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,282" Name="btn10" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,12,57" Name="lbl1" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,82" Name="lbl2" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,107" Name="lbl3" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,132" Name="lbl4" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,157" Name="lbl5" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,182" Name="lbl6" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,207" Name="lbl7" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,232" Name="lbl8" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,257" Name="lbl9" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,282" Name="lbl10" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Content="Pacakage info" HorizontalAlignment="Center" Width="Auto" Height="32" Name="lblPkgname" FontSize="16" FontWeight="Bold" Margin="20,371,2" Grid.RowSpan="2" />
<Slider x:Name="slider" HorizontalAlignment="Left" Margin="20,357,0" VerticalAlignment="Top" Width="484"/>
<Slider x:Name="slider1" HorizontalAlignment="Left" Margin="-148,205,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="326">
<Slider.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="89.89"/>
<TranslateTransform/>
</TransformGroup>
</Slider.RenderTransform>
</Slider>
</Grid>
namespace _3DTools
{
public class ScreenSpaceLines3D : ModelVisual3D
{
public static readonly DependencyProperty ColorProperty;
public static readonly DependencyProperty ThicknessProperty;
public static readonly DependencyProperty PointsProperty;
public ScreenSpaceLines3D();
public Color Color { get; set; }
public double Thickness { get; set; }
public Point3DCollection Points { get; set; }
public void MakeWireframe(Model3D model);
}
}
我要实现此功能: 当我移动水平滑块时,垂直线水平移动; 当我移动垂直滑块时,水平线垂直移动。
如何添加这种绑定?我尝试使用普通方法,但失败了。
解决方法
为水平滑块提供一个最小值和最大值:
%x = alloca fp128
store fp128 0xLE978D4FDF3B645A24000921CAC083126,fp128* %x
然后将转换偏移量应用于水平线,将OffsetY绑定到滑块的值:
<Slider x:Name="slider" Minimum="-1" Maximum="1" HorizontalAlignment="Left" Margin="20,357,0" VerticalAlignment="Top" Width="484" />
重复另一个轴。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。