Textbox width in a Cell Template

4 posts, 0 answers
  1. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 25 Mar 2012 Link to this post

    I have a cell template that contains several items:   Two images and one text box.

    The images optionally are displayed based on a condition and the text box is always visible.   However, I cannot seem to get the with to stretch to the full size of the cell template.   I have tried both WrapPanels and Grids and neither works.

    I have found that it appears to be related to the fact that I am not specifically setting the width of the cell.   When I set it to some value, then the text box seems to stretch as expected, but unfortunately, I need the width of the column to be auto sized based on the content (i.e. if the images need to be shown, then it should auto expand).

    What can I do to make the text box expand to the full width of the gridview cell?

    Or, is there a better way to do what I am attempting?

    Here is my XAML code:

     

    <telerik:GridViewDataColumn Header="Base Price" HeaderTextAlignment="Center" MinWidth="50">
        <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Image Source="/PriceBook;component/Images/Pencil.png" Grid.Column="0"
                           Visibility="{Binding BasePrice.IsPriceChanged, Converter={StaticResource VisibilityConverter}}" />
                    <Image Source="/PriceBook;component/Images/Override.png" Grid.Column="1"
                           Visibility="{Binding BasePrice.IsPriceOverride, Converter={StaticResource VisibilityConverter}}" />
                    <TextBox Grid.Column="2" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
                             Text="{Binding BasePrice.Current, Mode=TwoWay, Converter={StaticResource PriceConverter}}"
                             BorderThickness="0" Background="Transparent" Foreground="{Binding BasePrice.Foreground}"
                             ToolTipService.ToolTip="{Binding BasePrice.ToolTipText}" TextAlignment="Right"></TextBox>
                </Grid>
            </DataTemplate>
        </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>



  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Mar 2012 Link to this post

    Hi,

     As I understand you want to have the column auto expanded so that both the Images and the TextBox to be shown with their full content(the column width is the exact width so that all the content inside is visible). I have tested your code snippet and as a result I got this result. The GridViewCell expands so that the full content in the TextBox is visible.  I have tested the Q1 2012 version of the controls.

    If I have somehow misunderstood your problem, please let me know where I am wrong.

    Greetings,
    Didie
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 28 Mar 2012 Link to this post

    I am using q3 2011 version. I am concerned with upgrading at this point as I don't want to encounter issues with upgrading. Can you verify if that was an issue that was fixed in later releases? If so, I will have to see if I can use the newer version. Thanks.
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Mar 2012 Link to this post

    Hi,

     I have tested the same code with version Q3 2011 and still the GridViewCell expands so that the full content in the TextBox is visible. So I cannot confirm anything related to this issue.
    I have attached the test project for your reference. Please note that I have not used any converters as I do not know how yours are defined.

    All the best,
    Didie
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top