【问题标题】:why can't I move a control within a tab in WPF designer?为什么我不能在 WPF 设计器的选项卡中移动控件?
【发布时间】:2013-08-21 10:50:02
【问题描述】:

我在一个选项卡中有一个组合框,我可以用鼠标改变它的大小、倾斜和旋转。但是,当我想移动它时,我不被允许。要更改组合框的位置,我必须在边距字段中手动输入坐标,这真的很烦人。为什么我不能简单地用鼠标拖动它来移动它?

更新

这实际上只发生在第二个选项卡中。在第一个选项卡中,我可以像预期的那样移动控件。 因此,我在我的 xaml 文件中剪切并粘贴了选项卡部分以更改选项卡顺序。现在,我可以在第一个选项卡(前第二个选项卡)中移动控件,而不能在第二个选项卡中移动控件。

对我来说,这听起来像是 WPF 设计器的错误...

更新 2

这是一个简单的测试用例。无法移动第二个选项卡中的 TestComboBox。

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="718" Width="728" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
    <TabControl HorizontalAlignment="Left" VerticalAlignment="Top">
        <TabItem Header="TabItem">
            <Grid Margin="0,10,0,4" Height="639" Width="708">
            </Grid>
        </TabItem>
        <TabItem Header="TabItem" Height="23">

            <Grid Margin="0,10,0,4" Height="639" Width="708">
                <ComboBox x:Name="TestComboBox" HorizontalAlignment="Left" Margin="84,10,0,0" Width="217" VerticalAlignment="Top" Height="22"/>
            </Grid>

        </TabItem>
    </TabControl>
</Window>

改变tab顺序后,TestComboBox可以移动:

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="718" Width="728" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
    <TabControl HorizontalAlignment="Left" VerticalAlignment="Top">
        <TabItem Header="TabItem" Height="23">

            <Grid Margin="0,10,0,4" Height="639" Width="708">
                <ComboBox x:Name="TestComboBox" HorizontalAlignment="Left" Margin="84,10,0,0" Width="217" VerticalAlignment="Top" Height="22"/>
            </Grid>

        </TabItem>            
        <TabItem Header="TabItem">
            <Grid Margin="0,10,0,4" Height="639" Width="708">
            </Grid>
        </TabItem>
    </TabControl>
</Window>

【问题讨论】:

  • 对我来说很好。如果可以,请显示您拥有的显示此问题的 xaml 代码。

标签: wpf visual-studio-2012 controls designer


【解决方案1】:

我遇到了同样的问题。通过将 TabControl 放置在网格中来解决它 - 请参见下面的代码。

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="718" Width="728" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
<Grid>    
<TabControl HorizontalAlignment="Left" VerticalAlignment="Top">
        <TabItem Header="TabItem" Height="23">

        <Grid Margin="0,10,0,4" Height="639" Width="708">
            <ComboBox x:Name="TestComboBox" HorizontalAlignment="Left" Margin="84,10,0,0" Width="217" VerticalAlignment="Top" Height="22"/>
        </Grid>

        </TabItem>            
        <TabItem Header="TabItem">
        <Grid Margin="0,10,0,4" Height="639" Width="708">
          <ComboBox x:Name="TestComboBox2" HorizontalAlignment="Left" Margin="84,10,0,0" Width="217"       VerticalAlignment="Top" Height="22"/>
            </Grid>
        </TabItem>
    </TabControl>
</Window>

【讨论】:

  • 你不是在&lt;/Window&gt;之前缺少&lt;/Grid&gt;吗?
【解决方案2】:

我刚刚尝试将TabControl 添加到新的 WPF 应用程序中。我添加了两个TabItem 控件,每个控件都有一个ComboBox。起初,Visual Studio 允许我在第一个选项卡中移动 ComboBox,但不能在第二个选项卡中移动。

在我移动第二个标签中的ComboBox 之后,当我松开鼠标按钮时,它会跳回到原来的位置。仔细观察,这是因为第一个 TabItem 中有一个 Grid,但第二个没有……也许你有类似的问题?

不过,在测试了你刚刚添加的代码之后,恐怕我没有遇到和你一样的问题。也许您应该重新启动 Visual Studio,甚至您的计算机?

【讨论】:

    【解决方案3】:

    我在使用 WPF 时遇到了同样的问题,但我这样做是为了“绕过”它。

    只需在您将要处理的网格之前评论网格。

    我知道在处理大型项目时这样做很痛苦,但这是我找到的唯一方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多