Xamarin Datatrigger弄乱了填充/边距

时间:2019-04-07 00:27:27

标签: xaml xamarin xamarin.forms

所以我得到了这两个带有混乱填充的按钮。所选按钮没有得到它应该具有的填充,而是被重置为0或其他值。

https://gyazo.com/93bb69132b8b9c30bd7c7ac5c43bff7e 这是当前的样子,如何使选中和未选中的外观相同?

我试图再次在数据触发中设置填充,但这并没有改变任何内容。

    <Grid Grid.Row="1" Grid.Column="0" Padding="10,5,10,5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Button Text="KGA" CommandParameter="KGA" Grid.Column="0" x:Name="KgaButton" HorizontalOptions="Fill"  Padding="10,5,10,5"
           Command="{Binding SelectCompanyCommand}">
            <Button.Triggers>
                <DataTrigger TargetType="Button" Binding="{Binding CompanyButton1}" Value="false">
                    <Setter Property="BackgroundColor"  Value="Default" />
                    <Setter Property="TextColor"  Value="Default" />
                    <Setter Property="Padding" Value="10,5,10,5"></Setter>

                </DataTrigger>
                <DataTrigger TargetType="Button" Binding="{Binding CompanyButton1}" Value="true">
                    <Setter Property="BackgroundColor"  Value="{StaticResource ThemeBkColor}" />
                    <Setter Property="TextColor"  Value="White" />
                    <Setter Property="Padding" Value="10,5,10,5"></Setter>
                </DataTrigger>
            </Button.Triggers>
        </Button>

        <Button  Text="CBL" CommandParameter="CBL" Grid.Column="1" x:Name="CblButton" HorizontalOptions="Fill"  Padding="10,5,10,5"
           Command="{Binding SelectCompanyCommand}" >
            <Button.Triggers>
                <DataTrigger TargetType="Button" Binding="{Binding CompanyButton2}" Value="false">
                    <Setter Property="BackgroundColor"  Value="Default" />
                    <Setter Property="TextColor"  Value="Default" />
                    <Setter Property="Padding" Value="10,5,10,5"></Setter>

                </DataTrigger>
                <DataTrigger TargetType="Button" Binding="{Binding CompanyButton2}" Value="true">
                    <Setter Property="BackgroundColor"  Value="{StaticResource ThemeBkColor}" />
                    <Setter Property="TextColor"  Value="White" />
                    <Setter Property="Padding" Value="10,5,10,5"></Setter>

                </DataTrigger>
            </Button.Triggers>
        </Button>

    </Grid>




 public bool CompanyButton1
        {
            get => companyButton1;
            set
            {
                companyButton1 = value;
                OnPropertyChanged();
            }
        }

0 个答案:

没有答案