วิธีขยายฟิลด์รายการที่ใช้งานอยู่ (Xamarin)

วิธีขยายฟิลด์รายการที่ใช้งานอยู่ ใช้งานอยู่ - สถานที่ที่จะกระตุ้นการเปิดใช้งานสถานที่นี้หลังจากกด

ภาพตัวอย่าง


person Community    schedule 10.05.2018    source แหล่งที่มา
comment
มีวิธีแก้ปัญหาหนึ่งช่วยคุณหรือไม่ โปรดโหวตและยอมรับว่าเป็นคำตอบที่เป็นประโยชน์... stackoverflow.com/help/someone-answers   -  person Johannes    schedule 16.05.2018


คำตอบ (3)


คุณสามารถใช้เมธอด Scale เพื่อเพิ่มขนาดของรายการ ทุกมุมมองมีคุณสมบัติ Scale ซึ่งสามารถใช้เพื่อเพิ่มขนาดได้

entry.Scale =2;
person Kalp    schedule 10.05.2018

ดู Visual State Manager ใหม่สำหรับ Xamarin Forms 3.0 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual-state-manager ซึ่งช่วยให้คุณจัดรูปแบบรายการของคุณสำหรับรัฐต่างๆ สถานะทั่วไปคือ Normal, Focused, Disabled คุณสามารถเช่น เพิ่ม FontSize และทำสิ่งต่าง ๆ กับรัฐอื่นด้วย (ดูที่ลิงค์ที่ให้ไว้)

สถานะที่คุณต้องการคือ Focused

<Entry FontSize="18">
<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">
        <VisualState x:Name="Normal">
            <VisualState.Setters>
                <Setter Property="BackgroundColor" Value="Lime" />
            </VisualState.Setters>
        </VisualState>

        <VisualState x:Name="Focused">
            <VisualState.Setters>
                <Setter Property="FontSize" Value="36" />
            </VisualState.Setters>
        </VisualState>

        <VisualState x:Name="Disabled">
            <VisualState.Setters>
                <Setter Property="BackgroundColor" Value="Pink" />
            </VisualState.Setters>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
person Johannes    schedule 10.05.2018

มีหลายวิธีในการบรรลุเป้าหมายดังกล่าว

หนึ่งในนั้นคือการเปลี่ยนแปลงคุณสมบัติตำแหน่ง เช่น Margin:

<ContentPage.Resources>
    <ResourceDictionary>
        <Style TargetType="Entry">
            <Style.Setters>
                <Setter Property="Margin" Value="20,30,30,30"/>
                <Setter Property="HorizontalOptions" Value="FillAndExpand"/>
                <Setter Property="VerticalOptions" Value="Center"/>
                <Setter Property="BackgroundColor" Value="AliceBlue"/>
            </Style.Setters>
        </Style>
        <Style TargetType="Image">
            <Style.Setters>
                <Setter Property="HorizontalOptions" Value="Center"/>
                <Setter Property="VerticalOptions" Value="Center"/>
                <Setter Property="Margin" Value="10"/>
                <Setter Property="Source" Value="icon"/>
            </Style.Setters>
        </Style>
    </ResourceDictionary>
</ContentPage.Resources>
<StackLayout>
    <Grid BackgroundColor="Silver">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="60"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Image Grid.Column="0" Grid.Row="0"/>
        <Entry Grid.Column="1" Grid.Row="0"
               x:Name="txtName"
               Placeholder="Name"
               Focused="GrowEntry"
               Unfocused="ShrinkEntry"/>

        <Image Grid.Column="0" Grid.Row="1"/>
        <Entry Grid.Column="1" Grid.Row="1"
               x:Name="txtEmail"
               Placeholder="E-mail"
               BackgroundColor="AliceBlue"
               Focused="GrowEntry"
               Unfocused="ShrinkEntry"/>

        <Image Grid.Column="0" Grid.Row="2"/>
        <Entry Grid.Column="1" Grid.Row="2"
               x:Name="txtPassword"
               Placeholder="Password"
               Focused="GrowEntry"
               Unfocused="ShrinkEntry"/>
    </Grid>
    <BoxView Color="White"
             VerticalOptions="FillAndExpand"/>
</StackLayout>

และในโค้ดด้านหลัง GrowEntry และ ShrinkEntry:

private void GrowEntry(object sender, EventArgs args)
{
    var entry = (Entry)sender;

    entry.Margin = new Thickness(6, 12, 12, 12);
}

private void ShrinkEntry(object sender, EventArgs args)
{
    var entry = (Entry)sender;

    entry.Margin = new Thickness(20, 30, 30, 30);
}

คุณจะได้รับสิ่งนี้:

การใช้ตัวอย่าง

person Diego Rafael Souza    schedule 10.05.2018