如何在WPF中使用BasedOn进行材料设计?

时间:2019-05-09 04:00:31

标签: c# wpf material-design

我的XAML上有此代码

<Button Click="BtnSync_Click" Grid.Column="0" Style="{StaticResource MaterialDesignFloatingActionLightButton}" Margin="8,21,10,75" Command="{Binding SaveCommand}" materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding IsSaving}"
                            materialDesign:ButtonProgressAssist.Value="{Binding SaveProgress}" Background="Transparent" Height="Auto" Width="Auto" BorderBrush="{x:Null}">

      <materialDesign:PackIcon  Height="24" Width="24" Foreground="LightBlue">
             <materialDesign:PackIcon.Style>
                <Style TargetType="materialDesign:PackIcon" BasedOn="{StaticResource {x:Type materialDesign:PackIcon}}" >
                  <Setter  Property="Kind" Value="CloudSync" />
                     <Style.Triggers>
                        <DataTrigger Binding="{Binding IsSaveComplete}" Value="True">
                             <Setter Property="Kind" Value="Check" />
                                <DataTrigger.EnterActions>
                                     <BeginStoryboard>
                                          <Storyboard>
                                             <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.8" />
                                            </Storyboard>
                                         </BeginStoryboard>
                                     </DataTrigger.EnterActions>
                            </DataTrigger>
                         </Style.Triggers>
                 </Style>
          </materialDesign:PackIcon.Style>
     </materialDesign:PackIcon>
 </Button>

但是我在这行上得到了错误

BasedOn="{StaticResource {x:Type materialDesign:PackIcon}}"

它说类似{x:Type materialDesign:PackIcon Extension} could not be resolved

我该怎么办?我一直在互联网上搜索解决方案,但似乎还没有得到解决方案。

1 个答案:

答案 0 :(得分:0)

情节提要与基本控件无关。

这是没有基本控制的代码:

<ToggleButton Name="IsSaveComplete"
                      Margin="0, 32"/>

<Button Style="{StaticResource MaterialDesignFloatingActionLightButton}" 
        Margin="8,21,10,75" 
        Command="{Binding SaveCommand}" 
        materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding IsSaving}"
        materialDesign:ButtonProgressAssist.Value="{Binding SaveProgress}" 
        Background="Transparent" 
        Height="Auto" 
        Width="Auto" 
        BorderBrush="{x:Null}"
        Click="BtnSync_OnClick">

    <materialDesign:PackIcon  Height="24"
                              Width="24"
                              Foreground="LightBlue">
        <materialDesign:PackIcon.Style>
            <Style TargetType="materialDesign:PackIcon" >
                <Setter Property="Kind" Value="CloudSync" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=IsSaveComplete, Path=IsChecked}"
                                 Value="True">
                        <Setter Property="Kind"
                                Value="Check" />
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.8" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </materialDesign:PackIcon.Style>
    </materialDesign:PackIcon>
</Button>

输出:

enter image description here