Wpf usercontrols没有使用WPF在WPF窗口内调整大小 [英] Wpf usercontrols are not resizing inside a WPF window using WPF

查看:111
本文介绍了Wpf usercontrols没有使用WPF在WPF窗口内调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试在WPF中做出响应,我在用户控件中创建了用户控件我创建了我的设计,那个用户控件放入主窗口,这里我的问题是我面临的问题是当我尝试调整持有用户控件的主窗口的大小时,用户控件将不会跟随父窗口而不会调整大小。

我的用户控制代码

Hi All,
I am trying to responsives in WPF,i created user control in that user control i created my Design,That User control Put inside Main Window,here my problem is I am facing is that when I try to resize the main window holding the user control, the user control won't follow the parent window and not resize as well.
My User Control code

<UserControl x:Class="Class.View.UC1"

             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:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"

              mc:Ignorable="d" 

              Height="600" Width="576" MinHeight="600" MinWidth="576">
    <UserControl.Resources>
        <viewmodel:ExtractInfoVM x:Key="vm"></viewmodel:ExtractInfoVM>

    </UserControl.Resources>
    <UserControl.DataContext>
        <viewmodel:ExtractInfoVM></viewmodel:ExtractInfoVM>
    </UserControl.DataContext>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="10" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!--Row 0-->

        <Label  Grid.Column="0" Grid.Row="0"  MaxHeight="25" Content="Vendor:" Name="lblVendor"/>
        <ComboBox ItemsSource="{Binding VendorList}"  SelectedValue="{Binding SelectedVendor}"  Grid.Column="1"  

          x:Name="cboVendor"  Grid.ColumnSpan="4" />
        <!--Row 1-->
        <Label Grid.Column="0" Grid.Row="1" MaxHeight="25" Content="Server:" Name="lblServer"/>
        <ComboBox Grid.Column="1" ItemsSource="{Binding Servers}"  

                    SelectedValue="{Binding SelectedServer}"

                      x:Name="cboServer"  Grid.ColumnSpan="4"  Grid.Row="1" />
        <!--Row 2-->
         <Label Grid.Column="0" Grid.Row="2" MaxHeight="25" Content="DataBase:" Name="lblDataBase"/>
        <ComboBox Grid.Column="1" ItemsSource="{Binding Databases}"  

                    SelectedValue="{Binding SelectedDatabase}"

                      x:Name="cboDatabase"  Grid.ColumnSpan="4"  Grid.Row="2" />

         <!--Row 7-->
        <TextBox Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="3" Background="#FFEFECCD" Text="{Binding AnalysisInfo}" Name="txtDesciptoin" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" TextWrapping="NoWrap" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" BorderThickness="2" />
        <Border BorderBrush="Silver" BorderThickness="1" Grid.Column="3" Grid.Row="3" MaxHeight="120" Grid.ColumnSpan="2" >
            <ListBox Name="lstReferenc" 

                             SelectedItem="{Binding Path=SelectedGranularity,UpdateSourceTrigger=PropertyChanged}" 

         ItemsSource="{Binding Granularitylist, NotifyOnSourceUpdated=True}" SelectionMode="Multiple" Margin="103,8,9,8" IsEnabled="{Binding Path=AllPropertiesValid}" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding DetailValue}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>

                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">


                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                <Setter Property="Background" Value="Red" />
                            </DataTrigger>
                        </Style.Triggers>
                        <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
                    </Style>

                </ListBox.ItemContainerStyle>

            </ListBox>
        </Border>
        <Grid Grid.Row="3" Grid.Column="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="10*" />
                <RowDefinition Height="15*" />
                <RowDefinition Height="15*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Label Content="Granularity:" Grid.Column="0" Grid.Row="0" Height="25"   Name="label5" Grid.ColumnSpan="3"   />
            <Button Content="Select All"  Command="{Binding SelectAll}" Grid.ColumnSpan="2"

                        Grid.Column="0" Grid.Row="1" Height="23" HorizontalAlignment="Stretch"  Name="btnSelectAll"  Width="75" IsEnabled="{Binding Path=AllPropertiesValid}"  />
            <Button Content="Unselect All" Grid.Column="0" Grid.Row="2" Height="23" HorizontalAlignment="Stretch" Command="{Binding UnSelectAll}"

                        Name="btnUnselectAll"  Width="75"  IsEnabled="{Binding Path=AllPropertiesValid}" Grid.ColumnSpan="2" />
        </Grid>
    </Grid>
</UserControl>



and my Mainwindow code is


and my Mainwindow code is

<Window

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:View="clr-namespace:Class.View" x:Class="ELT_Data_Extractor.ELT_Data_Extract"

       

         Height="620" Width="586" WindowStartupLocation="CenterScreen">
    
        <View:DataBaseBrowser HorizontalAlignment="Center" Width="576" VerticalAlignment="Top" Height="550" Margin="1,0" />
        <Button x:Name="CancelButton" Content="Cancel"  Width="75" Height="23" HorizontalAlignment="Right" Margin="0,528,15,29"  Click="CancelButton_Click" />
        <Button x:Name="OKButton" Content="OK"  Width="75" Height="23" HorizontalAlignment="Right" Margin="0,528,101,29"  Click="OKButton_Click" />

    </Grid>
</Window>



When i maximize the window the usercontrol also fit it as well as window

could you please provide any solution to me.



What I have tried:



i Goodled this issue and i didn’t solve my issue.and i tried remove height and width for user control but it’s not working and i tried this below link solution also it’s not working

[^]

推荐答案

You have a fixed Width and Height and VerticalAlignment set to Top:

You have a fixed Width and Height and VerticalAlignment set to Top:
<View:DataBaseBrowser HorizontalAlignment="Center" Width="576" VerticalAlignment="Top" Height="550" Margin="1,0" />



To fix:


To fix:

<View:DataBaseBrowser HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="1,0" />


这篇关于Wpf usercontrols没有使用WPF在WPF窗口内调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆