我上传了我的窗口图片,在白色空间中我需要填充用户控件但我无法将其顶部,底部,左侧,右侧锚定,请建议我如何做到这一点,谢谢:)
XAML
<ribbon:RibbonWindow x:Class="H_Pro.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="H-Pro. Version 1.0.0" Height="394" Width="856" xmlns:my="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon" WindowState="Maximized" Loaded="RibbonWindow_Loaded">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<my:Ribbon x:Name="MainRibbon" Height="auto" Width="auto" AllowDrop="False" ClipToBounds="False" DataContext="{Binding}" Focusable="True" IsCollapsed="False" IsDropDownOpen="True" IsManipulationEnabled="False" IsMinimized="False">
<my:RibbonTab Header="Main">
<my:RibbonGroup Name="SecurityRibbonGroup" Header="Security" Width="100">
<my:RibbonButton Name="btnChangeUser" Label="Change User" LargeImageSource="/H-Pro;component/Images/1310403730_group.png" Click="btnChangeUser_Click">
</my:RibbonButton>
<my:RibbonButton Name="btnUserList" Label="Users List" LargeImageSource="/H-Pro;component/Images/1294319913_people.png" Click="btnUserList_Click" />
</my:RibbonGroup>
<my:RibbonGroup Name="BookingOperationsRibbonGroup" Header="Booking Informations" Width="auto">
<my:RibbonButton Label="New Booking" Name="btnNewBooking" LargeImageSource="/H-Pro;component/Images/1310421580_appointment-new.png" />
<my:RibbonButton Label="Booking List" Name="btnBookingList" LargeImageSource="/H-Pro;component/Images/booking.png"/>
</my:RibbonGroup>
<my:RibbonGroup Name="GuestRibbonGroup" Header="Guest Operations" Width="auto">
<my:RibbonButton Name="btnGuestDataBase" Label="Guest Database" LargeImageSource="/H-Pro;component/Images/dbd.png" />
<my:RibbonGroup />
<my:RibbonButton Label="Add New Guest"/>
<my:RibbonButton Label="Top Guests"/>
</my:RibbonGroup>
</my:RibbonTab>
<my:RibbonTab Header="Add/Edit" Name="AddEditRibbonTab">
<my:RibbonGroup Name="AddRooms" Header="Rooms" Width="auto">
<my:RibbonButton Label="Add/Edit Rooms" Name="btnAddEditRooms" LargeImageSource="/H-Pro;component/Images/1310459678_hotel4stars.png" />
</my:RibbonGroup>
</my:RibbonTab>
</my:Ribbon>
<Grid Grid.Row="1" Name="grid1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<DockPanel LastChildFill="False">
<StackPanel DockPanel.Dock="Top" Background="Yellow"></StackPanel>
<StackPanel DockPanel.Dock="Bottom" Background="White" Height="23">
<StatusBar Height="23" Name="MainStatusBar" Width="auto" />
</StackPanel>
<StackPanel DockPanel.Dock="Left" Background="AliceBlue" Width="49" Height="auto"/>
</DockPanel>
</Grid>
</Grid>
答案 0 :(得分:1)
将UserControl放在内容区域中并将其设置为“拉伸”:
<local:MyUserControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
这将确保它填充内容区域。
答案 1 :(得分:1)
一个建议:向网格添加另一行并将StatusBar移动到网格而不是DockPanel。
使用StackPanel之类的东西,如果将“高度/宽度”设置为“自动”,或者不指定“高度/宽度”,则默认情况下不会填充父控件。 Auto会根据需要占用尽可能多的空间。