如果canHide为true,则命令属性不起作用

时间:2018-08-11 16:59:20

标签: c# wpf xaml triggers

我下载了扩展器控件,现在我需要运行命令,但该命令不起作用。搜索之后,我发现当我伪造CanHide属性时该命令将运行,但是再次出现另一个问题,即该控件的视觉功能消失了(阴影,边框颜色...)

  

CanHide = True

    <Trigger Property="CanHide" Value="True">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Metro:MetroExpander}">
                    <Grid Background="#7FFFFFFF">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup>
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="height" Storyboard.TargetProperty="(Height)" To="0" Duration="0:0:0.15" />
                                        <DoubleAnimation Storyboard.TargetName="angle" Storyboard.TargetProperty="(Angle)" To="0" Duration="0:0:0.15" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="StartNormal">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="height" Storyboard.TargetProperty="(Height)" To="0" Duration="0:0:0" />
                                        <DoubleAnimation Storyboard.TargetName="angle" Storyboard.TargetProperty="(Angle)" To="0" Duration="0:0:0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Expand">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="height" Storyboard.TargetProperty="(Height)" To="{Binding ElementName=content,Path=ActualHeight}" Duration="0:0:0.15" />
                                        <DoubleAnimation Storyboard.TargetName="angle" Storyboard.TargetProperty="(Angle)" To="90" Duration="0:0:0.15" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="StartExpand">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="height" Storyboard.TargetProperty="(Height)" To="{Binding ElementName=content,Path=ActualHeight}" Duration="0:0:0" />
                                        <DoubleAnimation Storyboard.TargetName="angle" Storyboard.TargetProperty="(Angle)" To="90" Duration="0:0:0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Border BorderBrush="#e6e6e6" BorderThickness="0,0,0,1">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="iconWidth" Width="Auto" />
                                    <ColumnDefinition />
                                    <ColumnDefinition x:Name="hintWidth" Width="Auto" />
                                    <ColumnDefinition x:Name="algleWidth" Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Image Width="12" Height="12" Margin="10,0,0,0" VerticalAlignment="Center" Source="{TemplateBinding Icon}" Opacity="0.7" />
                                <Metro:MetroTextBlock Grid.Column="1" Text="{TemplateBinding Header}" Margin="10,8,5,8" VerticalAlignment="Center" HorizontalAlignment="Left" Opacity="0.65" />
                                <Metro:MetroBorder    Grid.Column="2" AutoCornerRadius="True" Margin="0,0,5,0" VerticalAlignment="Center" Background="{TemplateBinding HintBackground}">
                                    <Metro:MetroTextBlock VerticalAlignment="Center" Margin="8,1" Text="{TemplateBinding Hint}" Foreground="{TemplateBinding HintForeground}" />
                                </Metro:MetroBorder>
                                <Grid Grid.Column="3" Margin="10,0" VerticalAlignment="Center">
                                    <Polyline Points="0,0 5,5 0,10" Stroke="#000000" RenderTransformOrigin="0.5,0.5" Opacity="0.65">
                                        <Polyline.RenderTransform>
                                            <TransformGroup>
                                                <RotateTransform x:Name="angle" Angle="0" />
                                            </TransformGroup>
                                        </Polyline.RenderTransform>
                                    </Polyline>
                                </Grid>
                                <Metro:MetroFocusButton Grid.ColumnSpan="4" Foreground="#00000000" MouseMoveForeground="#0C000000" BorderThickness="0" MouseMoveBorderThickness="0" Command="Metro:MetroExpander.ButtonClickCommand" />
                            </Grid>
                        </Border>
                        <Grid x:Name="height" Grid.Row="1" Background="#00000000" Height="{Binding ActualHeight,ElementName=content}" ClipToBounds="True">
                            <Canvas x:Name="canvas" Height="{Binding ActualHeight,ElementName=content}" MinWidth="{Binding ActualWidth,ElementName=content}">
                                <Grid x:Name="content" ClipToBounds="True" MinWidth="{Binding ActualWidth,ElementName=canvas}">
                                    <ContentPresenter />
                                </Grid>
                            </Canvas>
                        </Grid>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Hint" Value="{x:Null}">
                            <Setter TargetName="hintWidth" Property="Width" Value="0" />
                        </Trigger>
                        <Trigger Property="Icon" Value="{x:Null}">
                            <Setter TargetName="iconWidth" Property="Width" Value="0" />
                        </Trigger>
                        <Trigger Property="Content" Value="{x:Null}">
                            <Setter TargetName="algleWidth" Property="MaxWidth" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Trigger>
  

CanHide = False

    <Trigger Property="CanHide" Value="False">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Metro:MetroExpander}">
                    <Grid Background="#7FFFFFFF">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Border BorderBrush="#e6e6e6" BorderThickness="0,0,0,1">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="iconWidth" Width="Auto" />
                                    <ColumnDefinition />
                                    <ColumnDefinition x:Name="hintWidth" Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Image Width="12" Height="12" Margin="10,0,0,0" VerticalAlignment="Center" Source="{TemplateBinding Icon}" Opacity="0.7" />
                                <Metro:MetroTextBlock Grid.Column="1" Text="{TemplateBinding Header}" Margin="10,8,5,8" VerticalAlignment="Center" HorizontalAlignment="Left" Opacity="0.65" />
                                <Metro:MetroBorder    Grid.Column="2" AutoCornerRadius="True" Margin="0,0,5,0" VerticalAlignment="Center" Background="{TemplateBinding HintBackground}">
                                    <Metro:MetroTextBlock VerticalAlignment="Center" Margin="8,1" Text="{TemplateBinding Hint}" Foreground="{TemplateBinding HintForeground}" />
                                </Metro:MetroBorder>
                            </Grid>
                        </Border>
                        <Border Grid.Row="1" Background="#7FFFFFFF" BorderBrush="#e6e6e6" BorderThickness="0,0,0,1">
                            <ContentPresenter />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Hint" Value="{x:Null}">
                            <Setter TargetName="hintWidth" Property="Width" Value="0" />
                        </Trigger>
                        <Trigger Property="Icon" Value="{x:Null}">
                            <Setter TargetName="iconWidth" Property="Width" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Trigger>

这是我的命令:

<Metro:MetroExpander Command="{mvvmc:NavigateCommand ControllerID='MainOperation',Action='Something'}"/>

0 个答案:

没有答案