0

Hello guys I create this UserControl

<UserControl x:Class="Pass.ConexionControl"
             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" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid MinWidth="300">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF8D9395"/>
                <GradientStop Color="Gainsboro" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition/>
            <RowDefinition Height="30"/>
            <RowDefinition/>
            <RowDefinition Height="30"/>
            <RowDefinition/>
            <RowDefinition Height="30"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="30" MinWidth="30" MaxWidth="30"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Foreground="White"/>
        <Label Grid.Row="2" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Foreground="White"/>
        <Label Grid.Row="4" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Foreground="White"/>
        <Label Grid.Row="6" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Foreground="White"/>

        <TextBox Grid.Row="1" ></TextBox>
        <TextBox Grid.Row="3"></TextBox>
        <TextBox Grid.Row="5"></TextBox>
        <TextBox Grid.Row="7"></TextBox>

        <Button Grid.Column="1" Grid.Row="1" Click="Button_Click"></Button>
        <Button Grid.Column="1" Grid.Row="3" Click="Button_Click_1"></Button>
        <Button Grid.Column="1" Grid.Row="5" Click="Button_Click_2"></Button>
        <Button Grid.Column="1" Grid.Row="7" Click="Button_Click_3"></Button>

    </Grid>
</UserControl>

The control is displayed correctly in the Visual Studio designer

When I try to add it to a ListBox in Window the width of the control contracts

I add the property MinWidth with 300, but, It is not the behavior I need

My MainWindow is like

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Pass" x:Class="Pass.MainWindow"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <ListBox x:Name="listMain" Margin="5">
            <local:ConexionControl />
        </ListBox>

    </Grid>
</Window>

In this case when the window is resized the list control will also change the size.

I need the user control resize regards the ListBox

In my user control I have 1 Grid with 2 Columns first column must rezise, second must keep size.

What should I change to accomplish this?

2
  • set your width of ListBox, then in user control set your first column width to Auto, second to *
    – Abin
    Oct 6, 2015 at 18:24
  • Check this
    – Abin
    Oct 6, 2015 at 18:27

1 Answer 1

0
<ListBox HorizontalContentAlignment="Stretch" Margin="0,0,164,86">
  <uc:UserControl1 />
</ListBox>

In your user-control :

<Grid>
...
<Grid.ColumnDefinitions>
  <ColumnDefinition Width="*"/>
  <ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>

Now when you resize your window everything will expand/contract accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.