WPF ReactiveUI控件-占用所有可用空间

时间:2018-08-02 07:32:55

标签: c# wpf xaml reactiveui

我知道在WPF中,可以通过将控件放置在底座中来使其占用所有可用空间。如果不需要该空间,我的反应式UI控件根本不会拉伸。我已经试过了Dockpanel,但它似乎不适用于Reactiveui:ViewModelViewHost控件。

这在我的shell视图中:

<DockPanel x:Name="ToolbarDockPanel" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
    <reactiveui:ViewModelViewHost x:Name="ToolbarView" Width="{Binding ActualWidth , ElementName=ToolbarDockPanel}"/>
</DockPanel>

这是我的观点:

<UserControl x:Class="ICRx.App.UI.Shell.Toolbar.ToolbarView"
         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:ICRx.App.UI.Shell.Toolbar"
         mc:Ignorable="d" 
         d:DesignHeight="100" d:DesignWidth="768" MinWidth="">
    <Grid x:Name="ToolbarGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="35"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="85"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="85"/>
        </Grid.ColumnDefinitions>        
        <Button x:Name="OpenButton"    Content="Open"    Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left"  Margin="5,10,5,5" VerticalAlignment="Top" Width="75"/>
        <Button x:Name="CaptureButton" Content="Capture" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left"  Margin="5,5,5,5"  VerticalAlignment="Top" Width="75"/>
        <Button x:Name="SaveButton"    Content="Save"    Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left"  Margin="5,5,5,10" VerticalAlignment="Top" Width="75"/>
        <Button x:Name="EditButton"    Content="Edit"    Grid.Row="0" Grid.Column="3" HorizontalAlignment="Right" Margin="5,10,5,5" VerticalAlignment="Top" Width="75"/>
        <Grid x:Name="TemplateGrid" Grid.Row="0" Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="TemplateLabelColumn" Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label x:Name="TemplateLabel"
               Grid.Column="0"
               Content="Template"
               Margin="5,0,0,0"
               HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <ComboBox x:Name="TemplateComboBox" Grid.Column="1" Margin="5,10,5,5"/>
        </Grid>
        <Grid x:Name="FilterGrid" Grid.Row="1" Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label x:Name="FilterLabel"
               Grid.Column="0"
               Content="Filter"
               Width="{Binding ActualWidth, ElementName=TemplateLabel}"
               Margin="5,0,0,0"
               HorizontalContentAlignment="Right"
               HorizontalAlignment="Left" VerticalAlignment="Center"/>
            <ComboBox x:Name="FilterComboBox" Grid.Column="1" Margin="5,5,5,5"/>
        </Grid>
    </Grid>
</UserControl>

1 个答案:

答案 0 :(得分:2)

尝试将 Horizo​​ntalAlignment =“ Stretch” VerticalAlignment =“ Stretch” 添加到ViewModelViewHost。 (如果失败,请尝试 Horizo​​ntalContentAlignment / VerticalContentAlignment )。我记得其中一个会拉伸您的内容以占用整个可用空间。