.net 拉伸我的用户控件有什么问题

.net 拉伸我的用户控件有什么问题,.net,wpf,.net,Wpf,我希望来自用户控件的图片能够覆盖整个黄色背景,而不仅仅是那条细线 我已经尽了一切可能,但我仍然有这个问题 我的主窗口 <Window x:Class="DBTool.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:View="clr-nam

我希望来自用户控件的图片能够覆盖整个黄色背景,而不仅仅是那条细线

我已经尽了一切可能,但我仍然有这个问题

我的主窗口

<Window x:Class="DBTool.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:View="clr-namespace:DBTool.View"
    xmlns:ViewModel="clr-namespace:DBTool.ViewModel"
    Title="MainWindow" Height="332" Width="528"  >

<Window.Resources>
    <!-- These four templates map a ViewModel to a View. -->
    <DataTemplate DataType="{x:Type ViewModel:SelectDataBaseViewModel}">
        <View:SelectDataBase />
    </DataTemplate>

    <DataTemplate DataType="{x:Type ViewModel:MySqlPageViewModel}">
        <View:MySqlPageView />
    </DataTemplate>

</Window.Resources>



<Grid ShowGridLines="True" HorizontalAlignment="Stretch" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

    <ToolBar  Grid.Row = "0" Height="26" HorizontalAlignment="Stretch" VerticalAlignment="Top" Name="toolBar1"  Width="Auto" DockPanel.Dock="Top"  />
    <!-- <View:SelectDataBase x:Name="DetailView"/>-->



    <Grid  VerticalAlignment="Bottom" Grid.Row = "2"  HorizontalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition/>
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Button Grid.Row="0" Grid.Column="4" Background="Azure" Margin="10"   Command="{Binding Path=MoveNextCommand}" >Next</Button>

            <Button Grid.Row="0" Grid.Column="3" Background="Azure" Margin="10" Command="{Binding Path=MovePreviousCommand}">Previous</Button>

        </Grid>
        <Border Background="Yellow" Grid.Row = "1">
             <HeaderedContentControl VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" Content="{Binding Path=CurrentPage}" Header="{Binding Path=CurrentPage.DisplayName}" />
        </Border>
    </Grid>       

下一个
以前的

用户控件

<UserControl x:Class="DBTool.View.SelectDataBase"
         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" 
         mc:Ignorable="d" VerticalContentAlignment="Stretch"
         VerticalAlignment="Stretch" d:DesignHeight="300" d:DesignWidth="300" >

<UserControl.Background  >
    <ImageBrush  Stretch="UniformToFill" ImageSource="..\Resources\DBSelection.jpg" ></ImageBrush >
</UserControl.Background >

<Grid VerticalAlignment="Stretch">
    <!--<RadioButton Content="MySQL" Height="16" HorizontalAlignment="Left" Margin="36,112,0,0" Name="radioButton1" VerticalAlignment="Top" />
    <RadioButton Content="MsSQL" Height="16" HorizontalAlignment="Left" Margin="36,134,0,0" Name="radioButton2" VerticalAlignment="Top" />-->
    <ItemsControl FontWeight="Normal" ItemsSource="{Binding Path=AvailableBeanTypes}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <RadioButton Content="{Binding Path=DisplayName}" IsChecked="{Binding Path=IsSelected}" GroupName="BeanType" Margin="2,3.5"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

</Grid>

会很高兴得到任何帮助,只是解决不了这个问题:-(


快速浏览后,我的最佳猜测是主窗口中的
行定义

<Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>


也许可以尝试将所有控件的高度都更改为一个固定的数字,看看这是否可以解决问题?

因为HeaderedContentControl没有明确地将默认高度设置为Auto,而Auto是由用户控件中的网格高度定义的。而且,由于也没有设置该高度,因此它将被设置为ItemsControl的大小,在本例中为Auto仅为两个单选按钮的高度。若要解决此问题,必须明确设置Items控件的高度。

在ImageBrush中,使用Uniform而不是UniformToFill

对不起,您错了,因为边框占用了正确的空间,但边框中的内容没有拉伸。