M
M
Mikhail Usotsky2016-10-28 11:04:24
WPF
Mikhail Usotsky, 2016-10-28 11:04:24

Is there such a possibility of extended processing depending on the state of the numeric flag?

There is a standard button. The ControlTemplate for Button describes the style behaviors for the IsEnable, IsMouseOver, and IsPressed states. Is there such a possibility of custom processing depending on the property in C# code? For example, a property in C# code can take the numbers 0, 1, 2, and 3. So, depending on the number in the behavior, for example, IsEnable, the button should be painted in one color out of four.
I searched on the Internet and made the following test code on a separate program:

<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
            <Border BorderBrush="LightGray" BorderThickness="1" CornerRadius="3" Name="border"
                    TextBlock.Foreground="LightGray" Background="Gray">
                <ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}"></ContentPresenter>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="local:PeakHelper.IsPeak" Value="True">
                    
                </Trigger>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="border" Property="Background" Value="DarkGray"></Setter>
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter TargetName="border" Property="BorderBrush" Value="Yellow"></Setter>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

public class PeakHelper : DependencyObject
    {
        public static readonly DependencyProperty IsPeakProperty = DependencyProperty.RegisterAttached("IsPeak", typeof(bool), typeof(PeakHelper), new PropertyMetadata(false));

        public static void SetIsPeak(DependencyObject target, Boolean value)
        {
            target.SetValue(IsPeakProperty, value);
        }
        public static bool GetIsPeak(DependencyObject target)
        {
            return (bool)target.GetValue(IsPeakProperty);
        }
    }

But I ran into a problem: for some reason this C# code does not see the namespace: it swears at the property trigger Property="local:PeakHelper.IsPeak".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Zolotov, 2016-10-28
@Aquarius-Michael

Google attached depency property and triggers. Which one of these is right for you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question