WPF Usercontrol块调整大小

时间:2014-07-11 16:05:58

标签: c# wpf user-controls

我有这个UserControl,我不希望它可以调整大小。 我已经设置了最大值和混合宽度和高度,但它仍然可以调整大小。 有没有其他方法可以阻止UserControl上的这个属性?我知道如何在一个窗口中执行它,但是我无法将此控件插入到窗口中,我需要像它一样阻止resize属性。

<UserControl x:Class="Tanino.WPFPlayer.Views.OpenDiscView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="220.79" Width="543" MinHeight="220.79" MinWidth="543" MaxHeight="220.79" MaxWidth="543">


<Grid Margin="10">
    <Grid.RowDefinitions>
        <RowDefinition Height="13*"/>
        <RowDefinition Height="auto" MinHeight="34"/>
        <RowDefinition Height="auto" MinHeight="17"/>
        <RowDefinition Height="23*"/>
        <RowDefinition Height="auto" MinHeight="42"/>
    </Grid.RowDefinitions>

    <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Stretch" Margin="1, 5">
        <RadioButton Content="DVD" x:Name="SelectedDvd" Margin="10,0"/>
        <RadioButton Content="Bluray" x:Name="SelectedBluRay" Margin="10,0"/>
    </StackPanel>

    <Grid Grid.Row="2" Margin="1, 5">
        <Separator HorizontalAlignment="Left" Height="3" Margin="15,0,15,0" VerticalAlignment="Top" Width="511"/>
    </Grid>

    <Grid Grid.Row="3" Margin="1,21,1,24">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition/>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Column="0" Margin="5,0"  Width="auto" Content="Disc Device"/>
        <ComboBox  Grid.Column="1" Margin="5,0" ItemsSource="{Binding ComboPaths}" SelectedItem="{Binding SelectedPath}"/>
            <Button Grid.Column="2" Margin="5,0" Width="25" BorderThickness="1">
            <Button.Background>
                <ImageBrush ImageSource="resources/finder-toolbar-eject.png"/>
            </Button.Background>
        </Button>
        <Button Grid.Column="3" HorizontalAlignment="Right" Margin="5,0" Content="Browse..." x:Name="SelectFolder"/>
    </Grid>

    <StackPanel Orientation="Horizontal" Grid.Row="4" HorizontalAlignment="Right" Margin="0,5,1,5" Width="170">
        <Button Margin="5,10,5,0" Width="75" Content="Play" x:Name="Ok"/>
        <Button Margin="5,10,5,0" Width="75" Content="Cancel" x:Name="Cancel"/>
    </StackPanel>
    <GroupBox Header="Disc Selection" HorizontalAlignment="Center" Margin="1,10,0,0" VerticalAlignment="Top" Height="149" Grid.RowSpan="4" Width="522">
        <Image HorizontalAlignment="Left" Height="37" Margin="444,-3,0,0" VerticalAlignment="Top" Width="83" Source="resources/logo2.png"/>

    </GroupBox>
</Grid>

提前致谢

2 个答案:

答案 0 :(得分:1)

将用户控件放在带有

的窗口中

ResizeMode="NoResize"

<Window x:Class="MyEditor.Views.EditorWindow"
        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:views="clr-namespace:Tanino.WPFPlayer.Views"
        mc:Ignorable="d"
        ResizeMode="NoResize"
        Title="Editor Window">
    <views:OpenDiscView />
</Window>

See link for more details

答案 1 :(得分:1)

如果您不想调整控件的大小,请不要在内部的网格中使用auto*。使用特定值。