【问题标题】:How to remove a Label and Entry with a switch in Xamarin如何在 Xamarin 中使用开关删除标签和条目
【发布时间】:2020-05-14 08:34:37
【问题描述】:

我正在尝试使用 x:Name="MS" 开关删除标签首付和条目首付,并将条目的文本/值更改为“0”。这是我的 *.xaml 代码

'''

   <Label Text="Purchased price"
            Margin="0,100,0,0" Padding="13,0,0,0" />
    <Entry Placeholder="Price $$"
           x:Name="price"
           Keyboard="Numeric"
           Margin="130,-30,40,0"
           Opacity="1" Rotation="0"
           TranslationX="16" />

    <Label  Text="Mortgage ??"
            Margin="0,10,0,0" Padding="13,0,0,0"/>
    <Switch IsToggled="false"
            Margin="130,-30,40,0"
            x:Name="MS"/>


    <Label Text="Downpayment"
           Margin="0,10,0,0" Padding="13,0,0,0"/>
    <Entry Placeholder="Down Payment"
           x:Name="Downpayment"
           Text="DP"
           Keyboard="Numeric"
           Margin="130,-30,40,0"
           Opacity="1" Rotation="0"
           TranslationX="16" />

'''

【问题讨论】:

    标签: xamarin xamarin.forms xamarin.ios


    【解决方案1】:

    Toggled 事件添加处理程序

    <Switch IsToggled="false" Toggled="SwitchToggled" ... />
    

    然后

    protected void SwitchToggled(object sender, ToggledEventArgs e)
    {
      // true if toggled
      if (e.Value)
      {
        Downpayment.IsVisible = false;
        DownpaymentLabel.IsVisible = false;
        price.Text = "0";
      }
    }
    

    【讨论】:

    • 只需要在标签上加上 x:Name="DownpaymentLabel" 即可。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 2019-04-05
    • 2018-06-13
    • 2015-06-08
    • 1970-01-01
    • 2020-04-15
    • 2018-07-19
    相关资源
    最近更新 更多