Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么双向数据绑定在WPF中不起作用?_C#_Wpf_Xaml_Data Binding - Fatal编程技术网

C# 为什么双向数据绑定在WPF中不起作用?

C# 为什么双向数据绑定在WPF中不起作用?,c#,wpf,xaml,data-binding,C#,Wpf,Xaml,Data Binding,我正在做一个小的大学项目,在那里我需要读一个包含一些表和函数的Lua文件,然后把它做成一个形状。完成了 问题是当我试图让它互动时。这是我的XAML: <Window x:Class="Gemi.WPF.VentanaPrincipal" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/20

我正在做一个小的大学项目,在那里我需要读一个包含一些表和函数的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对象的setter。有什么想法吗


还有,为什么我需要绑定椭圆的中心?如果我只绑定DragCanvas的“Top/Bottom/Left/Right”,所有点都在0,0处绘制,这会导致一个问题,因为我无法将点进一步向左或向上拖动到它们最初所在的位置。

这可能是因为drag-n-drop不会修改Canvas.Left和Canvas.Top,而是使用转换转换


绑定到此转换可能很棘手,因为我希望拖放系统将此转换添加到转换组中。因此,它不会更新您添加到转换中的转换。

可能是缺少模式=双向?你应该想看看。我从WPF搬到了XNA。。。WPF似乎没有游戏所需的“果汁”。这取决于游戏的类型。基本上,我想做一个在屏幕上呈现形状的游戏。您可以拖动形状的边缘,形状的属性应该实时更新。WPF能够做到这一点吗?是的,WPF可以做到这一点,但您必须对某些部分进行编码,此形状修改不是内置的。这不是删除此问题的原因。你的问题得到了回答,但你发现你还需要别的东西。