拉伸我的usercontrol有什么问题

时间:2011-02-17 22:31:20

标签: .net wpf

我希望来自usercontrol的图片会遍布整个黄色背景而不仅仅是那条细线。

我已经伸展了所有可能的东西,但我仍有这个问题

我的主窗口

<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>

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

My code

3 个答案:

答案 0 :(得分:2)

由于您的HeaderedContentControl未明确设置高度,因此默认设置为Auto,这是由用户控件中的网格高度定义的。因为它也没有设置然后它将被设置为ItemsControl的大小,在这种情况下,它只是2个单选按钮的高度。要修复它,您必须显式设置ItemsControl的高度。

答案 1 :(得分:0)

快速浏览后我的最佳猜测是主窗口中的RowDefinitions

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

也许尝试将所有这些高度更改为固定数字,看看是否可以修复它?

答案 2 :(得分:0)

在ImageBrush中给出Uniform而不是UnifromToFill