样式触发器属性不会更改XAML中元素的宽度

时间:2018-05-15 15:38:02

标签: c# wpf xaml

我正在尝试触发元素的 TASK [It's time for MD5 checking on OSPF interfaces. Let's download full show run] ****** task path: /etc/ansible/showrun-routers.yml:19 <IP address> using connection plugin network_cli (was local) Using module file /usr/lib/python2.7/dist-packages/ansible/modules/network/ios/ios_command.py <omited> 属性并在XAML中调整宽度并且它正在工作,但问题是如果我在元素的标记中定义默认或静态宽度属性,那么这不起作用。为什么? 工作代码

IsMouseOver

但是如果我现在添加<UserControl x:Class="IntelliVentory.UserControls.SideMenuBarControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:IntelliVentory.UserControls" mc:Ignorable="d" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:userControls="clr-namespace:IntelliVentory.UserControls" TextElement.Foreground="{DynamicResource MaterialDesignBody}" Background="{DynamicResource MaterialDesignPaper}" TextElement.FontWeight="Medium" TextElement.FontSize="14" FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" d:DesignHeight="450" d:DesignWidth="800"> <Grid> <ItemsControl Margin="50"> <ItemsControl.Resources> <Style x:Key="ScaleStyle" TargetType="materialDesign:ColorZone"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Width" Value="300" /> </Trigger> </Style.Triggers> </Style> </ItemsControl.Resources> <materialDesign:ColorZone Name="ColorZone1" Style="{StaticResource ScaleStyle}" Height="50" Mode="PrimaryDark" Padding="16" CornerRadius="3" materialDesign:ShadowAssist.ShadowDepth="Depth3" /> <materialDesign:ColorZone Margin="0 5 0 0" Name="ColorZone2" Style="{StaticResource ScaleStyle}" Height="50" Mode="PrimaryDark" Padding="16" CornerRadius="3" materialDesign:ShadowAssist.ShadowDepth="Depth3" /> <materialDesign:ColorZone Margin="0 5 0 0" Name="ColorZone3" Style="{StaticResource ScaleStyle}" Height="50" Mode="PrimaryDark" Padding="16" CornerRadius="3" materialDesign:ShadowAssist.ShadowDepth="Depth3" /> </ItemsControl> </Grid> 属性,那么此触发器属性将无法在第一个ColorZone元素width="40"上工作,它将无效。

Name="colorZone1"

1 个答案:

答案 0 :(得分:2)

您需要在样式中设置默认宽度。

        <Style x:Key="ScaleStyle" TargetType="materialDesign:ColorZone">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Width" Value="300" />
                </Trigger>
            </Style.Triggers>
             <Style.Setters>
                <Setter Property="Width" Value="40"/>
             </Style.Setters>
        </Style>