开发者

Malfunction the width of WpfDatagridColumn

i have this WpfDatagrid and I need a exact width column and i have a problem.

I need the column "Code" has 100 in width. I need the column "Description" Auto is to occupy the most it can I need the column "Active" and "Edit" occupy 100 of width

The way you pass me the code remains the same as in the picture, and I can not fill the entire screen. Anybody can explain me that I am doing wrong? [img]http://www.imagengratis.org/images/capturadh5jd.jpg[/img] http://www.imagengratis.org/images/capturadh5jd.jpg

   <Pa开发者_运维知识库ge x:Class="CHGUV.Guia.Farmacoterapeutica.Pages.Maestros.TramoEdad.TramoEdadPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:my1="clr-namespace:WpfCCLibrary;assembly=WpfCCLibrary"

      Title="Tramos de edad" xmlns:my="clr-namespace:WpfCCLibrary.Control;assembly=WpfCCLibrary" xmlns:mic="http://schemas.microsoft.com/wpf/2008/toolkit" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="720" d:DesignWidth="1050" KeyDown="Page_PreviewKeyDown" Loaded="Page_Loaded">
    <Page.Resources>
        <DataTemplate x:Key="ItemTemplate">
            <StackPanel>
                <TextBlock Text="{Binding CFG_CAT_FAR_PosologiaTipo_Tipo}"/>
                <TextBlock Text="{Binding CFG_CAT_FAR_PosologiaTipo_Descripcion}"/>

            </StackPanel>
        </DataTemplate>
    </Page.Resources>
    <Grid>
<Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1.5" StartPoint="0,0">
                <GradientStop Color="#FF87BDEB" Offset="0" />
                <GradientStop Color="White" Offset="1" />
            </LinearGradientBrush>
        </Grid.Background>
        <my:WpfLabel Content="Código" HorizontalAlignment="Left" Margin="39,0,0,107" Name="wpfLabel1" Height="21" VerticalAlignment="Bottom" />
            <my:WpfTextBox Height="23" HorizontalAlignment="Left" Margin="121,0,0,107" Name="TextBoxCodigo" VerticalAlignment="Bottom" Width="134" MaxLength="10" KeyDown="TextBoxCodigo_PreviewKeyDown" />
            <my:WpfLabel Content="Descripción" Height="22" HorizontalAlignment="Left" Margin="38,0,0,71" Name="wpfLabel2" VerticalAlignment="Bottom" Width="64" />
            <my:WpfTextBox Height="23" HorizontalAlignment="Left" Margin="121,0,0,71" Name="TextBoxDescripcion" VerticalAlignment="Bottom" Width="581" MaxLength="150" KeyDown="TextBoxDescripcion_PreviewKeyDown" />
            <my:WpfCheckBox Content="Modificable" Height="16" HorizontalAlignment="Left" Margin="324,0,0,110" Name="CheckBoxModificable" VerticalAlignment="Bottom" Estilo="StlWpfCheckBoxAzul" />
        <my:WpfCheckBox Content="Activo" Height="16" HorizontalAlignment="Left" Margin="428,0,0,110" Name="CheckBoxActivo" VerticalAlignment="Bottom" Estilo="StlWpfCheckBoxAzul" />
        <my:WpfImage Height="24" HorizontalAlignment="Left" Margin="261,0,0,106" Name="ImageCodigoNoNume"  Stretch="Fill" VerticalAlignment="Bottom" Width="24" Source="/CHGUV.Guia.Farmacoterapeutica.Pages;component/Images/Cancel_peq.png" Visibility="Collapsed" >

            </my:WpfImage>
            <Label Content="Tipo posología" Height="25" HorizontalAlignment="Left" Margin="33,0,0,36" Name="label1" VerticalAlignment="Bottom" />
        <my:WpfComboBox Height="23" HorizontalAlignment="Left" Margin="121,0,0,36" Name="comboBoxPosologia" VerticalAlignment="Bottom" Width="131" ItemsSource="{Binding CFG_CAT_FAR_PosologiaTipo}" Estilo="StlWpfComboBoxBlackAzul" />
        <my:WpfStatusBar  Visibility="Visible" Height="25" VerticalAlignment="Bottom" BorderThickness="0.7"  BorderBrush="#FF688CAF">
            <!--<my:WpfStatusBar.BorderThickness BorderBrush="White" BorderThickness="15" CornerRadius="15" />-->

            <my:WpfStatusBar.Background>

                <LinearGradientBrush EndPoint="0.0,5.5" StartPoint="0,0">
                    <GradientStop Color="#4682B4" Offset="0" />
                    <!--#FF688CAF-->
                    <GradientStop Color="White" Offset="1" />

                </LinearGradientBrush>
            </my:WpfStatusBar.Background>
            <StatusBarItem Name="statusBarItem" HorizontalAlignment="Left" Foreground="White" />
            <StatusBarItem Name="statusBarNoModificable" HorizontalAlignment="Center" Foreground="White" FontWeight="Bold" />
            <StatusBarItem Name="statusBarItemEstado" HorizontalAlignment="Right" Foreground="White" />
        </my:WpfStatusBar>
        <my:WpfDataGrid AutoGenerateColumns="False" Estilo="StlWpfDataGridAlternatingRows" Estilo_Header="WpfDataGridColumnHeaderAzul" Margin="12,12,12,147" Name="dataGridTramoEdad" SelectionChanged="dataGridTramoEdad_SelectionChanged" IsReadOnly="True">
            <my:WpfDataGrid.Columns>
                <mic:DataGridTextColumn Binding="{Binding CFG_CAT_FAR_TramoEdad_CodTramoEdad}" Header="Código" SortDirection="Ascending" SortMemberPath="CFG_CAT_FAR_TramoEdad" Width="80" MaxWidth="80" MinWidth="80">
                    <mic:DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextAlignment" Value="Right" />

                        </Style>
                    </mic:DataGridTextColumn.ElementStyle>
                </mic:DataGridTextColumn>
                <mic:DataGridTextColumn Binding="{Binding CFG_CAT_FAR_TramoEdad_DescripcionTramo}" Header="Descripción" SortMemberPath="CFG_CAT_FAR_TramoEdad"  Width="Auto">
                    <mic:DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping" Value="Wrap" />
                        </Style>
                    </mic:DataGridTextColumn.ElementStyle>
                </mic:DataGridTextColumn>
                <!--<mic:DataGridTextColumn Binding="{Binding CFG_CAT_FAR_TramoEdad_TipoPosol}" Header="Tipo posología" SortDirection="Ascending" SortMemberPath="CFG_CAT_FAR_TramoEdad" Width="15" />-->
                <mic:DataGridCheckBoxColumn Binding="{Binding CFG_CAT_FAR_TramoEdad_Modificable}" Header="Modificable" SortMemberPath="CFG_CAT_FAR_TramoEdad" Width="80" MaxWidth="100" MinWidth="100" />
                <mic:DataGridCheckBoxColumn Binding="{Binding CFG_CAT_FAR_TramoEdad_Activo}" Header="Activo" SortMemberPath="CFG_CAT_FAR_TramoEdad" Width="80" MaxWidth="100" MinWidth="100" />
                <!--<mic:DataGridTextColumn Binding ="{Binding CFG_CAT_FAR_TramoEdad_UsuarioAlta}" Header="Usuario alta" SortDirection="Ascending" SortMemberPath="CFG_CAT_FAR_TramoEdad" Width="125"/>-->

                <!--<mic:DataGridTextColumn Binding ="{Binding CFG_CAT_FAR_TramoEdad_UsuarioModificable}" Header="Usuario modificación" SortDirection="Ascending" SortMemberPath="CFG_CAT_FAR_TramoEdad" Width="125"/>-->
            </my:WpfDataGrid.Columns>
        </my:WpfDataGrid>
    </Grid>

</Page>


I assume English is not your primary language but it is not clear what you want. You could assign Width to a Converter and calculate the width there.


If I understand you right, you want the Width of your column to always take up enough space to display every single item in that column, but not to stretch and fill the entire area.

That's a problem because by default DataGrid's are Virtualized so non-visible items are not loaded until you scroll to them.

You can either

  • Set your DataGridColumnWidth equal to * so it takes up all remaining space
  • Disable Virtualization (not recommend due to performance reasons)
  • Hook up something in your DataGrid's loaded event that evaluates the contents of every item in that column, calculates the render width of them, and sets the column's width equal to the highest number (also not really recommended due to initial load time)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜