我正在做一个小型大学项目,我需要读取一个带有一些表和函数的 Lua 文件并从中制作一个形状。就这样完成了。
问题是当我尝试使其具有交互性时。这是我的 XAML:
<Window x:Class="Gemi.WPF.VentanaPrincipal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Gemi.WPF"
Title="GEMI - Geometría Interactiva!" Height="350" Width="525">
<Window.Resources>
<local:DoblesAPunto x:Key="DoblesAPunto"/>
</Window.Resources>
<DockPanel LastChildFill="True" Background="White">
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Figura Seleccionada: "/>
<ComboBox Name="cbFiguras" HorizontalAlignment="Stretch" Grid.Column="1"
ItemsSource="{Binding Path=Figuras}" DisplayMemberPath="Nombre" SelectionChanged="cbFiguras_FiguraSeleccionada" />
</Grid>
<ScrollViewer DockPanel.Dock="Bottom" Name="scrollPropiedades"
Height="Auto" VerticalScrollBarVisibility="Auto">
<DockPanel Name="dpPropiedades">
<StackPanel Orientation="Vertical" Name="spNombres" DockPanel.Dock="Left"/>
<StackPanel Orientation="Vertical" Name="spValores" DockPanel.Dock="Right" Margin="10, 0, 0, 0"/>
</DockPanel>
</ScrollViewer>
<DockPanel LastChildFill="True">
<Slider Name="controlZoom" DockPanel.Dock="Bottom" Value="1"
Maximum="50" Minimum="0.1" Orientation="Horizontal" ToolTip="Controla el zoom de la figura"/>
<ItemsControl x:Name="cnvFigura" ItemsSource="{Binding Puntos}">
<ItemsControl.LayoutTransform>
<ScaleTransform
CenterX="0" CenterY="0"
ScaleX="{Binding ElementName=controlZoom,Path=Value}"
ScaleY="{Binding ElementName=controlZoom,Path=Value}"/>
</ItemsControl.LayoutTransform>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Path Fill="Black" local:DragCanvas.CanBeDragged="True"
local:DragCanvas.Top="{Binding Y, Mode=TwoWay}"
local:DragCanvas.Left="{Binding X, Mode=TwoWay}">
<Path.Data>
<EllipseGeometry RadiusX="5" RadiusY="5">
<EllipseGeometry.Center>
<MultiBinding Converter="{StaticResource DoblesAPunto}">
<Binding Path="X" />
<Binding Path="Y" />
</MultiBinding>
</EllipseGeometry.Center>
</EllipseGeometry>
</Path.Data>
<Path.ToolTip>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="X = " Grid.Column="0" Grid.Row="0"/>
<TextBlock Text="{Binding X}" Grid.Column="1" Grid.Row="0"/>
<TextBlock Text="Y = " Grid.Column="0" Grid.Row="1"/>
<TextBlock Text="{Binding Y}" Grid.Column="1" Grid.Row="1"/>
</Grid>
</Path.ToolTip>
</Path>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:DragCanvas IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
</DockPanel>
</Window>
有问题的问题是绑定没有更新。即使我拖动构成 DataTemplate 的省略号,也永远不会调用“Punto”对象的设置器。有任何想法吗?
另外,为什么我似乎需要绑定椭圆的中心?如果我只绑定 DragCanvas 的 Top/Bottom/Left/Right 所有点都绘制在 0,0 处,这会引发一个问题,因为我不能将这些点拖到更左也不能拖到它们最初所在的位置。