gpt4 book ai didi

wpf - 为什么我不能在 WPF 设计器的选项卡内移动控件?

转载 作者:行者123 更新时间:2023-12-01 03:54:42 25 4
gpt4 key购买 nike

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

更新

这实际上只发生在第二个选项卡中。在第一个选项卡中,我可以按预期移动控件。
所以我在我的 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>

最佳答案

我有同样的问题。通过将 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>

关于wpf - 为什么我不能在 WPF 设计器的选项卡内移动控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18355409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com