這是我第一次使用WPF中的GridSplitter。我試圖讓用戶調整包含2個主要控件的網格。頂部是一個數據網格,下面是一個包含地圖圖像的按鈕。 這是它在設計器中的樣子。我有一個單獨的行,只是爲了網格。行定義的xaml是Gridsplitter不需要的行爲
<Grid.RowDefinitions>
<RowDefinition Height="37" />
<RowDefinition Height="274*" />
<RowDefinition Height="13*"/>
<RowDefinition Height="272*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
有趣的是,如果我將它移動下來,GridSplitter似乎可行。然後我可以根據需要移動它並正常運行。但是,如果我將分離器移動到上面定義的行所在的行上,我無法再將其移動下去。我只能繼續向前推進。
我附上了一個gif鏈接,顯示我說的here的行爲。
我想知道如何使GridSplitter函數在向上或向下移動時相同,就像現在一樣,只有從初始起始位置向下移動時,功能纔是正確的。
任何幫助表示讚賞。
更新:這是用戶控件保持電網全XAML:
<UserControl x:Class="LWDCM.Views.JobsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LWDCM.Views"
xmlns:Properties="clr-namespace:LWDCM.Properties"
xmlns:Utility="clr-namespace:LWDCM.Utility"
xmlns:Styles="clr-namespace:LWDCM.Styles"
xmlns:gif="https://github.com/XamlAnimatedGif/XamlAnimatedGif"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:Converters="clr-namespace:LWDCM.Converters"
mc:Ignorable="d"
Name="jobsControl"
MinWidth="800"
MinHeight="600"
>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Styles/AppStyles.xaml" />
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="MainGrid"
Margin="0,0,0,0"
Background="#26598c"
>
<!--<Grid.Background>
<LinearGradientBrush ColorInterpolationMode="SRgbLinearInterpolation"
StartPoint="0.5, 0.0"
EndPoint="0.5, 1.0">
<GradientStopCollection>
<GradientStop Color="#FF111111"
Offset="0.0" />
<GradientStop Color="#FF333333"
Offset="0.5" />
<GradientStop Color="#FF111111"
Offset="1.0" />
</GradientStopCollection>
</LinearGradientBrush>
</Grid.Background>-->
<Grid.RowDefinitions>
<RowDefinition Height="37" />
<RowDefinition Height="274*" />
<RowDefinition Height="13*"/>
<RowDefinition Height="272*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<Grid.Resources>
<ContextMenu x:Key="ListViewContextMenu">
<MenuItem x:Name="ContextRename"
Header="{x:Static Properties:Resources.RenameJob}"
Command="{Binding RenameJobCommand}" />
<MenuItem x:Name="ContextSetJobsiteAddress"
Header="{x:Static Properties:Resources.SetJobsiteAddress}"
Command="{Binding UpdateJobSiteAddressCommand}" />
<MenuItem x:Name="ContextSetCustomerAddress"
Header="{x:Static Properties:Resources.SetCustomerAddress}"
Command="{Binding UpdateCustomerInformationCommand}" />
<MenuItem x:Name="ContextSetContractorAddress"
Header="{x:Static Properties:Resources.SetContractorAddress}"
Command="{Binding UpdateContractorInformationCommand}" />
<MenuItem x:Name="ContextEditWorkOrderNumber"
Header="{x:Static Properties:Resources.EditWorkOrderNumber}"
Command="{Binding EditWorkOrderNumberCommand}" />
<Separator/>
<MenuItem x:Name="ExportToKML"
Header="{x:Static Properties:Resources.ExportToKML}"
Command="{Binding ExportToKMLCommand}"/>
</ContextMenu>
<Converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
</Grid.Resources>
<DataGrid x:Name="JobListView"
AutoGenerateColumns="False"
ItemsSource="{Binding UnitStatusCollection, Mode=TwoWay}"
CanUserDeleteRows="False"
Style="{StaticResource JobGridViewStyle}"
SelectedItem="{Binding JobsListViewSelectedUnitInfo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Utility:DataGridColumnsBehavior.BindableColumns="{Binding DataGridColumns}"
ContextMenu="{StaticResource ListViewContextMenu}"
Margin="10,0,10,2"
Grid.Row="1"
SelectionMode="Single"
SelectionUnit="FullRow"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
RowStyle="{StaticResource DataGridRowStyle}"
CellStyle="{StaticResource DataGridCellStyle}"
AlternationCount="2"
CanUserResizeRows="False"
HorizontalGridLinesBrush="#d6d6d6"
VerticalGridLinesBrush="#d6d6d6"
Background="#EAEAEA"
>
<!--This is to allow double clicks to open a job in LWD 3x-->
<DataGrid.InputBindings>
<MouseBinding Gesture="LeftDoubleClick"
Command="{Binding OpenInLWD3xCommand}" />
<KeyBinding Key="Return"
Command="{Binding OpenInLWD3xCommand}" />
<KeyBinding Key="F5"
Command="{Binding RefreshCommand}"/>
</DataGrid.InputBindings>
<DataGrid.Resources>
<Converters:DoubleNanVisibilityConverter x:Key="DoubleNanVisibilityConverter" />
<Converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
</DataGrid.Resources>
</DataGrid>
<Button Cursor="Hand"
Grid.ZIndex="0"
Margin="10,2,10,1"
Grid.Row="3"
x:Name="cmdMapImage"
Visibility="{Binding JobsListViewSelectedUnitInfo, Converter={StaticResource NullVisibilityConverter}}"
Style="{StaticResource MapButtonStyle}"
Command="{Binding ShowMapOnlineCommand}">
<Image x:Name="mapImage"
Source="{Binding DisplayedImage}"
Tag="{Binding JobId}"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality">
</Image>
</Button>
<Rectangle Fill="#26598c"
Grid.ZIndex="1"
Margin="0,10,7,0"
Grid.Row="3"
Height="46"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Width="226"
RadiusY="3.667"
RadiusX="3.667"
Focusable="False"/>
<Button Grid.ZIndex="2"
Command="{Binding ScanForwardCommand}"
x:Name="scrollRightButton"
Margin="0,20,15,0"
HorizontalAlignment="Right"
Width="30"
Height="26"
VerticalAlignment="Top"
Grid.Row="3">
<Image x:Name="scrollRight"
Source="/Assets/Down-30px-tall.png"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality">
</Image>
</Button>
<Button Grid.ZIndex="2"
Command="{Binding ScanBackwardCommand}"
x:Name="scrollLeftButton"
Margin="0,20,50,0"
RenderTransformOrigin="1,-0.617"
HorizontalAlignment="Right"
Width="30"
Height="26"
VerticalAlignment="Top"
Grid.Row="3">
<Image x:Name="scrollLeft"
Source="/Assets/Up-30px-tall.png"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality">
</Image>
</Button>
<ComboBox x:Name="ScanSizesComboBox"
Grid.ZIndex="2"
ItemsSource="{Binding ScanSizes}"
SelectedItem="{Binding SelectedScanSize, Mode=TwoWay}"
ToolTip="{Binding (Validation.Errors)[0].ErrorContent}"
Margin="0,20,85,0"
HorizontalAlignment="Right"
Width="61"
Height="26"
VerticalAlignment="Top"
Grid.Row="3" />
<Button x:Name="OpenLWD"
Grid.ZIndex="2"
Command="{Binding OpenInLWD3xCommand}"
Margin="0,20,150,0"
HorizontalAlignment="Right"
Width="75"
Height="26"
VerticalAlignment="Top"
Grid.Row="3"
Padding="0"
Background="#26598c">
<Image x:Name="openIn3x"
Source="/Assets/LWD-button.png"
Tag="{Binding JobId}"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality"
Height="27">
</Image>
</Button>
<DockPanel Grid.Row="0"
LastChildFill="False"
Grid.RowSpan="4">
<Menu x:Name="menu"
DockPanel.Dock="Top"
IsTabStop="False"
FontSize="13"
VerticalAlignment="Top"
Background="WhiteSmoke"
Height="27">
<MenuItem x:Name="FileMenu"
Header="{x:Static Properties:Resources.File}"
Background="Transparent" FontFamily="Arial">
<MenuItem x:Name="BluetoothUpload"
Header="{x:Static Properties:Resources.UploadBluetoothJob}"
IsEnabled="True"
Command="{Binding OpenLWD3xBluetoothCommand}" />
<MenuItem x:Name="FileUpload"
Header="{x:Static Properties:Resources.UploadLocalFile}"
IsEnabled="True"
Command="{Binding AddLocalJobCommand}" />
<Separator />
<MenuItem x:Name="FileLogout"
Header="{x:Static Properties:Resources.Logout}"
IsEnabled="True"
Command="{Binding LogoutCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
</MenuItem>
<MenuItem x:Name="ViewMenu"
Header="{x:Static Properties:Resources.View}"
Background="Transparent">
<MenuItem x:Name="ColumnOptions"
Header="{x:Static Properties:Resources.ColumnOptions}"
Background="Transparent"
Command="{Binding ShowColumnOptionsDialogCommand}" />
<MenuItem x:Name="DisplayUnits"
Header="{x:Static Properties:Resources.DisplayUnits}"
Background="Transparent"
Command="{Binding ShowUnitsSelectionCommand}" />
<Separator />
<MenuItem x:Name="ViewRefresh"
IsEnabled="True"
Header="Re_fresh"
Command="{Binding RefreshCommand}"
/>
<!--<MenuItem x:Name="ViewOptions" Header="_Options" />-->
</MenuItem>
<MenuItem x:Name="HelpMenu"
Header="{x:Static Properties:Resources.Help}"
Background="Transparent">
<MenuItem x:Name="HelpOpen"
Header="{x:Static Properties:Resources.OnlineHelp}" />
<Separator />
<MenuItem x:Name="HelpAbout"
Header="{x:Static Properties:Resources.About}"
Command="{Binding ShowAboutDialogCommand}" />
<MenuItem x:Name="DeleteUnits"
Header="Delete all Units"
Command="{Binding RemoveUnitsCommand}"/>
</MenuItem>
</Menu>
</DockPanel>
<GridSplitter x:Name="gridSplitter" Grid.Row="2" Width="Auto" MinHeight="5" MaxHeight="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0,4,0,4" />
</Grid>
</UserControl>
這裏是JobGridViewStyle:
<Style x:Key="JobGridViewStyle" TargetType="DataGrid">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Background" Value="WhiteSmoke" />
<Setter Property="SelectionMode" Value="Single" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="10,0,10,0" />
</Style>
什麼控制是在分配器下,在什麼面板你存儲它?我們可以看到這種觀點的完整xaml嗎? – Karolis
我使用包含控件的網格的xaml更新了帖子 – KSF
此網格存儲在UserControl或Window中嗎?因爲我已經嘗試了你粘貼的代碼,並且它確實工作正常。 – Karolis