Click here to Skip to main content
15,513,143 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to stop text boxes from being stretched while typing a long text without using Multi-line feature as "AcceptReturns" or "Wrap" properties With preserving auto size feature for Controls & Fonts when the screen resized
Here is my XAML Code for my Page:
XML
<grid showgridlines="False">
     <grid.rowdefinitions>
            <rowdefinition height="*" />
            <rowdefinition height="2*" />
            <rowdefinition height="2*" />
            <rowdefinition height="*" />
            <rowdefinition height="*" />
            <rowdefinition height="*" />
        </grid.rowdefinitions>
        <grid.columndefinitions>
            <columndefinition width="*" />
            <columndefinition width="1.5*" />
            <columndefinition width="*" />
            <columndefinition width="1.5*" />
        </grid.columndefinitions>
        <textblock text="{Binding Path=Customer_LblCompanyName, Source={StaticResource Resources}, FallbackValue='Company Name', diagnostics:PresentationTraceSources.TraceLevel=High}"
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="0"
                   Grid.Row="0" />
        <textblock text="{Binding Path=Customer_LblResponsibleNames, Source={StaticResource Resources}, FallbackValue='Responsible Name', diagnostics:PresentationTraceSources.TraceLevel=High}"
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="0"
                   Grid.Row="1" />
        <textblock text="{Binding Path=Customer_LblPhoneNos, Source={StaticResource Resources}, FallbackValue='Phone No.(s)',diagnostics:PresentationTraceSources.TraceLevel=High}"
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="0"
                   Grid.Row="2" />
        <textblock text="{Binding Path=Customer_LblCompActivity, Source={StaticResource Resources}, FallbackValue='Company Activity', diagnostics:PresentationTraceSources.TraceLevel=High}">
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="0"
                   Grid.Row="3" />
        <textblock text="{Binding Path=Customer_LblContractDate, Source={StaticResource Resources}, FallbackValue='Contract Date', diagnostics:PresentationTraceSources.TraceLevel=High}"
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="2"
                   Grid.Row="0" />
        <textblock text="{Binding Path=Customer_LblFreeSupportEndDate, Source={StaticResource Resources}, FallbackValue='Free Support End Date', diagnostics:PresentationTraceSources.TraceLevel=High}"
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="2"
                   Grid.Row="1" />
        <textblock text="{Binding Path=Customer_LblCompAddress, Source={StaticResource Resources}, FallbackValue='Address', diagnostics:PresentationTraceSources.TraceLevel=High}"
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="2"
                   Grid.Row="2" />
        <textblock text="{Binding Path=Customer_LblCompEmail, Source={StaticResource Resources}, FallbackValue='Email', diagnostics:PresentationTraceSources.TraceLevel=High}"
                   Style="{StaticResource SystemTextBlocksStyle}"
                   Grid.Column="2"
                   Grid.Row="3" />
        <viewbox grid.column="1">
                 Grid.Row="0"
                 Stretch="Uniform">
            <textbox grid.column="1">
                     Grid.Row="0"
                     Style="{StaticResource SystemTextBoxStyle}" />
        </textbox></viewbox>
        <viewbox grid.column="1">
                 Grid.Row="1"
                 Stretch="Fill">
            <grid grid.column="1">
                  Grid.Row="1"
                  VerticalAlignment="Stretch">
                <grid.rowdefinitions>
                    <rowdefinition height="*" />
                    <rowdefinition height="2*" />
                </grid.rowdefinitions>
                <textbox x:name="txtBox_ResponsibleName" xmlns:x="#unknown">
                         Style="{StaticResource SystemTextBoxStyle}"
                         Grid.Row="0"
                         Margin="10,10,50,10" />
                <Button x:Name="btn_AddResponsible"
                        Grid.Row="0"
                        Margin="270,10,10,10"
                        Style="{StaticResource RoundedAddButton}"
                        Click="btn_AddResponsible_Click" />
                <listbox x:name="lstBox_Responsibles">
                         Style="{StaticResource SystemLstBoxStyle}"
                         Grid.Row="1"                         local:ImageSourceExtension.ImageSource="/images/Responsible.png"
                         ItemContainerStyle="{StaticResource SystemLstBoxItemStyle}">
                   <!--Tag="/images/Responsible.png"-->
                </listbox>
            </textbox></grid>
        </viewbox>
        <viewbox grid.column="1">
                 Grid.Row="2"
                 Stretch="Fill">
            <grid grid.column="1">
                  Grid.Row="2"
                  VerticalAlignment="Stretch">
                <grid.rowdefinitions>
                    <rowdefinition height="*" />
                    <rowdefinition height="2*" />
                </grid.rowdefinitions>
                <textbox x:name="txtBox_PhoneNo" xmlns:x="#unknown">
                         Style="{StaticResource SystemTextBoxStyle}"
                         Grid.Row="0"
                         Margin="10,10,50,10" />
                <Button x:Name="btn_AddPhoneNo"
                        Grid.Row="0"
                        Margin="270,10,10,10"
                        Style="{StaticResource RoundedAddButton}"
                        Click="btn_AddPhoneNo_Click" />
                <listbox x:name="lstBox_PhoneNos">
                         Style="{StaticResource SystemLstBoxStyle}"
                         Grid.Row="1"
                         local:ImageSourceExtension.ImageSource="/images/PhoneNo.png"
                         ItemContainerStyle="{StaticResource SystemLstBoxItemStyle}">
                    <!--Tag="/images/PhoneNo.png"-->
                </listbox>
            </textbox></grid>
        </viewbox>
        <viewbox grid.column="1">
                 Grid.Row="3"
                 Stretch="Uniform" >
            <grid width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Viewbox}}, Path=ActualWidth}">
                  Height="Auto">
                <textbox grid.column="1">
                         Grid.Row="3"
                         Margin="10,10,6,10"
                         ScrollViewer.VerticalScrollBarVisibility="Disabled"
                         Style="{StaticResource SystemTextBoxStyle}" />
            </textbox></grid>
        </viewbox>
        <viewbox grid.column="3">
                 Grid.Row="0"
                 Stretch="Uniform">
            <datepicker grid.column="3">
                        Grid.Row="0"
                        Style="{StaticResource SystemDatePickerStyle}"
                        CalendarStyle="{StaticResource styleCalendar}" />
        </datepicker></viewbox>
        <viewbox grid.column="3">
                 Grid.Row="1"
                 Stretch="Uniform">
            <datepicker grid.column="3">
                        Grid.Row="1"
                        Style="{StaticResource SystemDatePickerStyle}"
                        CalendarStyle="{StaticResource styleCalendar}" />
        </datepicker></viewbox>
        <viewbox grid.column="3">
                 Grid.Row="2"
                 Stretch="Uniform">
            <textbox grid.column="3">
                     Grid.Row="2"
                     Style="{StaticResource SystemTextBoxStyle}" />
        </textbox></viewbox>
        <viewbox grid.column="3">
                 Grid.Row="3"
                 Stretch="Uniform">
            <textbox grid.column="3">
                     Grid.Row="3"
                     Style="{StaticResource SystemTextBoxStyle}" />
        </textbox></viewbox>
        <viewbox grid.row="5">
                 Grid.ColumnSpan="4"
                 Stretch="Uniform"
                 HorizontalAlignment="Right">
            <stackpanel grid.row="5">
                        Grid.ColumnSpan="4"
                        Orientation="Horizontal">
                <Button x:Name="btn_Save"
                        Margin="10"
                        Content="{Binding Path=Customer_btn_SaveContent, Source={StaticResource Resources}, FallbackValue='Save'}"
                        Style="{StaticResource ButtonStyle}"
                        Click="btn_Save_Click" />
                <Button x:Name="btn_Cancel"
                        IsCancel="True"
                        Margin="10"
                        Content="{Binding Path=Customer_btn_CancelContent, Source={StaticResource Resources}, FallbackValue='Cancel'}"
                        Style="{StaticResource ResourceKey=ButtonStyle}" />
        </viewbox>
            <textbox grid.column="1">
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Stretch"
                     FontStretch="UltraCondensed"
                     Margin="10"
                     Grid.Row="4"
                     Text="TextBox"
                     VerticalContentAlignment="Center">
            </textbox>
    </textblock></textblock></textblock></textblock></textblock></textblock></textblock></textblock></grid>


What I have tried:

I tried to put them in Grid in Viewbox and Bind the Width of Grid to ActualWidth of Viewbox but that work when Viewbox Stretch property is Fill and also when it fill It doesn't preserve the Margin that I set in Style File
<grid width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Viewbox}}, Path=ActualWidth}">
Height="Auto">
Posted
Updated 5-Dec-17 2:27am
v2
Comments
Irina Pykhova 16-Feb-16 5:44am    
please, insert correct xaml inside pre block, I tried to edit it to show correctly, but apparently something got lost

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900