使用户控件延伸到所有给定空间

发布于 2024-10-17 07:35:16 字数 3575 浏览 1 评论 0原文

我有一些用户控件,我将其放入窗口控件中,我不想在用户控件中具有固定大小,我希望它能够捕获我放置它的所有空间。我应该在我的代码中添加什么?

   <UserControl x:Class="DBTool.View.SelectDataBase"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            >


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

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

            <DockPanel LastChildFill="True" >


        <ToolBar Height="26" HorizontalAlignment="Stretch" VerticalAlignment="Top" Name="toolBar1"  Width="Auto" DockPanel.Dock="Top"  />

        <Grid  VerticalAlignment="Bottom" DockPanel.Dock="Bottom"  >
            <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>

            <TextBox Name="txtInput" Grid.Column="1"/>
            <Label Content="{Binding Text, ElementName=txtInput, 
                     UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" />


        </Grid>
       <!-- <View:SelectDataBase x:Name="DetailView"/>-->
        <Border Background="White" Grid.Column="1" Grid.Row="0">
            <HeaderedContentControl 
        Content="{Binding Path=CurrentPage}" 
        Header="{Binding Path=CurrentPage.DisplayName}" 
        />
        </Border>
    </DockPanel>


</Window>

在此处输入图像描述

但我想看到图像占据整个空白区域。

I have some user control that I am putting in a window control , i dont want to have a fixed size in the user control i want it to catch all the space were i put it . What should i add to my code ?

   <UserControl x:Class="DBTool.View.SelectDataBase"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            >


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

    <Grid>
     <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>
</UserControl>

My window code

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

            <DockPanel LastChildFill="True" >


        <ToolBar Height="26" HorizontalAlignment="Stretch" VerticalAlignment="Top" Name="toolBar1"  Width="Auto" DockPanel.Dock="Top"  />

        <Grid  VerticalAlignment="Bottom" DockPanel.Dock="Bottom"  >
            <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>

            <TextBox Name="txtInput" Grid.Column="1"/>
            <Label Content="{Binding Text, ElementName=txtInput, 
                     UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" />


        </Grid>
       <!-- <View:SelectDataBase x:Name="DetailView"/>-->
        <Border Background="White" Grid.Column="1" Grid.Row="0">
            <HeaderedContentControl 
        Content="{Binding Path=CurrentPage}" 
        Header="{Binding Path=CurrentPage.DisplayName}" 
        />
        </Border>
    </DockPanel>


</Window>

enter image description here

But i want to see the image take the whole white space there .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-10-24 07:35:16

您需要了解面板(网格、堆栈等)及其属性。高度和宽度属性,如果我记得在 wpf 中有一个“*”值,它按百分比执行。

这是一个很棒的 wpf 教程

http://www.wpftutorial.net/

you need to learn about panels (grid, stack etc) and their properties. The height and width properties and if i remember in wpf there is a "*" value that does it by percentage.

this is a agreat wpf tutorial

http://www.wpftutorial.net/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文