Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在不破坏控件模板功能的情况下绑定到属性?_C#_Wpf_Controltemplate - Fatal编程技术网

C# 如何在不破坏控件模板功能的情况下绑定到属性?

C# 如何在不破坏控件模板功能的情况下绑定到属性?,c#,wpf,controltemplate,C#,Wpf,Controltemplate,我制作了一个控件模板,它的目标类型是if按钮。 它的两个事件触发器属于IsEnable和IsNoteable属性。当控制模板启用时,我将不透明度设置为100%,当不启用时,我将不透明度设置为40% 在我的GUI窗口中,我定义了一个新按钮,如下所示: <Button x:Name="JoinB" IsEnabled="{Binding Path=GroupStatus,Converter={StaticResource EnableConverter}}"

我制作了一个控件模板,它的目标类型是if按钮。 它的两个事件触发器属于IsEnable和IsNoteable属性。当控制模板启用时,我将不透明度设置为100%,当不启用时,我将不透明度设置为40%

在我的GUI窗口中,我定义了一个新按钮,如下所示:

<Button x:Name="JoinB" 
        IsEnabled="{Binding Path=GroupStatus,Converter={StaticResource EnableConverter}}"  
        Template="{DynamicResource JoinButtonStyle}" />

}

而不是像您当前那样为启用/禁用状态使用两个不同的触发器

将它们与进入/退出合并为一个触发器


你能提供你的模板代码吗?我写了一个转换器和一个控制模板,发现不透明度更新正确。请张贴JoinButtonStyle的代码以及EnableConverter;在主要问题中添加了我的代码绑定时,是否在Convert方法中设置了断点以查看是否调用了它以及使用了哪些参数?是的,我使用断点进行了检查,结果良好。根据枚举返回true或false
<Button x:Name="JoinB" IsEnabled="false"  
        Template="{DynamicResource JoinButtonStyle}" />
<ControlTemplate x:Key="JoinButtonStyle" TargetType="{x:Type Button}">
    <ControlTemplate.Resources>
        <Storyboard x:Key="OnMouseEnter1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.BlurRadius)" Storyboard.TargetName="rectangle">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="8"/>
            </DoubleAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Color)" Storyboard.TargetName="rectangle">
                <EasingColorKeyFrame KeyTime="0:0:0.2" Value="#FF00BC02"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="OnMouseLeave1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.BlurRadius)" Storyboard.TargetName="rectangle">
                <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="2"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="OnPreviewMouseLeftButtonDown1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
                <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0.7"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="label">
                <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0.7"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="OnPreviewMouseLeftButtonUp1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="label">
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="onNotEnabled">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
                <EasingDoubleKeyFrame KeyTime="0" Value="0.4"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="onEnabled">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </ControlTemplate.Resources>
    <Grid x:Name="grid" VerticalAlignment="Center" HorizontalAlignment="Center" Background="#00000000">
        <Rectangle x:Name="rectangle" HorizontalAlignment="center" VerticalAlignment="center" Height="30"  Width="90" RadiusX="15" RadiusY="15" StrokeThickness="1" Stroke="#FF58A6FD">
            <Rectangle.Effect>
                <DropShadowEffect BlurRadius="2" ShadowDepth="0" Color="#FF58A6FD"/>
            </Rectangle.Effect>
        </Rectangle>
        <Label x:Name="label" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FF58A6FD" Content="Join"/>
    </Grid>
    <ControlTemplate.Triggers>
        <EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonUp">
            <BeginStoryboard x:Name="OnPreviewMouseLeftButtonUp1_BeginStoryboard" Storyboard="{StaticResource OnPreviewMouseLeftButtonUp1}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="UIElement.PreviewMouseLeftButtonDown">
            <BeginStoryboard x:Name="OnPreviewMouseLeftButtonDown1_BeginStoryboard" Storyboard="{StaticResource OnPreviewMouseLeftButtonDown1}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave">
            <BeginStoryboard x:Name="OnMouseLeave1_BeginStoryboard" Storyboard="{StaticResource OnMouseLeave1}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseEnter">
            <BeginStoryboard x:Name="OnMouseEnter1_BeginStoryboard" Storyboard="{StaticResource OnMouseEnter1}"/>
        </EventTrigger>
        <Trigger Property="IsEnabled" Value="False">
            <Trigger.EnterActions>
                <BeginStoryboard x:Name="OnMouseEnter1_BeginStoryboard1" Storyboard="{StaticResource onNotEnabled}"/>
            </Trigger.EnterActions>
        </Trigger>
        <Trigger Property="IsEnabled" Value="True">
            <Trigger.EnterActions>
                <BeginStoryboard x:Name="onEnabled_BeginStoryboard" Storyboard="{StaticResource onEnabled}"/>
            </Trigger.EnterActions>
        </Trigger>
    </ControlTemplate.Triggers>

</ControlTemplate>  
public class EnableToGroupStatusConverter:IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if ((ClientManager.DateGroupInfo.GroupStatusType)value == ClientManager.DateGroupInfo.GroupStatusType.CLOSED)
        {
            return false;
        }
        else
        {
            return true;
        }

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}