Гость
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Изменение кнопки / 18 сообщений из 18, страница 1 из 1
12.10.2014, 16:38
    #38774367
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Всем привет. Можете помочь, как можно сделать, чтобы при наведении на кнопку, она наполовину меняла цвет? И еще при нажатии на кнопку менялся цвет с задержкой на несколько секунд? Также как можно сделать произвольную форму кнопки?
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
<Window x:Class="WpfApplication10.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <ControlTemplate x:Key="TemplateB" TargetType="Button">
            <Border BorderBrush="Orange" BorderThickness="3" CornerRadius="2" Name="bor"
                  TextBlock.Foreground="Red">
                <Border.Background>
                    <LinearGradientBrush>
                        <GradientStopCollection>
                            <GradientStop Offset="0" Color="Yellow"></GradientStop>
                            <GradientStop Offset="1" Color="Green"></GradientStop>
                        </GradientStopCollection>
                    </LinearGradientBrush>
                </Border.Background>
                <ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}"></ContentPresenter>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="bor" Property="Background" Value="Green"></Setter>
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter TargetName="bor" Property="Background" Value="Red"></Setter>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
    <Button Margin="10" Width="130" Height="130" Template="{StaticResource TemplateB}"></Button>
</Window>
...
Рейтинг: 0 / 0
12.10.2014, 17:27
    #38774389
EDUARD SAPOTSKI
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
...
Рейтинг: 0 / 0
13.10.2014, 23:38
    #38775724
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Как правильно использовать свойство KeyTime, что установить время задержки цвета при нажатии на кнопку?
...
Рейтинг: 0 / 0
14.10.2014, 11:18
    #38775951
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Slant-shadow,

для более детальной настройки поведения кнопки и изменения ей состояний лучший способ использовать StateManager, если лень, то можно использовать триггеры.
Вот простейший пример кнопки в которой состояние MouseOver наступает через секунду после того как Вы навели на неё мышкой, на основе этого примера сами догадаетесь как анимировать другие состояния.
Если эффект анимации не требуется, то можно использовать Duration 0
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
        <Style TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Border CornerRadius="3">
                                <Border.Background>
                                    <SolidColorBrush x:Name="BackgroundColor" Color="Goldenrod"/>
                                </Border.Background>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Border>
                            
                            <VisualStateManager.VisualStateGroups>
                                
                                <VisualStateGroup x:Name="CommonStates" >
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition To="MouseOver" GeneratedDuration="0:0:1"/>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" 
                                                            To="Firebrick" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" 
                                                            To="ForestGreen" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused"/>
                                    <VisualState x:Name="Unfocused" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>

                </Setter.Value>
            </Setter>
        </Style>
...
Рейтинг: 0 / 0
14.10.2014, 11:20
    #38775953
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Roman Mejtes,

не очень понял, что значит "наполовину меняла цвет"?
если нужно изменить цвет половины кнопки, то в шаблоне нужно создать не 1 бордюр, а несколько, либо использовать градиентую заливку и менять цвет одного из ГридентСтоперов.
...
Рейтинг: 0 / 0
14.10.2014, 12:55
    #38776140
Супер_Пав
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Посмотри вот такой пример:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
<!--  Button  -->
    <ControlTemplate x:Key="GlassButton" TargetType="{x:Type Button}">
        <ControlTemplate.Resources>
            <Storyboard x:Key="Timeline1">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="Timeline2">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
        </ControlTemplate.Resources>
        <Border BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="4,4,4,4">
            <Border x:Name="border" Background="#7F000000" BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="4,4,4,4">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.507*"/>
                        <RowDefinition Height="0.493*"/>
                    </Grid.RowDefinitions>
                    <Border Opacity="0" HorizontalAlignment="Stretch" x:Name="glow" Width="Auto" Grid.RowSpan="2" CornerRadius="4,4,4,4">
                        <Border.Background>
                            <RadialGradientBrush>
                                <RadialGradientBrush.RelativeTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="1.702" ScaleY="2.243"/>
                                        <SkewTransform AngleX="0" AngleY="0"/>
                                        <RotateTransform Angle="0"/>
                                        <TranslateTransform X="-0.368" Y="-0.152"/>
                                    </TransformGroup>
                                </RadialGradientBrush.RelativeTransform>
                                <GradientStop Color="#B28DBDFF" Offset="0"/>
                                <GradientStop Color="#008DBDFF" Offset="1"/>
                            </RadialGradientBrush>
                        </Border.Background>
                    </Border>
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Grid.RowSpan="2"/>
                    <Border HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="shine" Width="Auto" CornerRadius="4,4,0,0">
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.494,0.889" StartPoint="0.494,0.028">
                                <GradientStop Color="#99FFFFFF" Offset="0"/>
                                <GradientStop Color="#33FFFFFF" Offset="1"/>
                            </LinearGradientBrush>
                        </Border.Background>
                    </Border>
                </Grid>
            </Border>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Opacity" TargetName="shine" Value="0.4"/>
                <Setter Property="Background" TargetName="border" Value="#CC000000"/>
                <Setter Property="Visibility" TargetName="glow" Value="Hidden"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource Timeline1}"/>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard x:Name="Timeline2_BeginStoryboard" Storyboard="{StaticResource Timeline2}"/>
                </Trigger.ExitActions>
            </Trigger>                        
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <!--++++++++++-->   
...
Рейтинг: 0 / 0
14.10.2014, 12:58
    #38776145
Супер_Пав
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Это шаблон, использовать его вот так:
Код: xml
1.
2.
3.
4.
5.
<Button Width="75"  Height="23" Foreground="#FFFFFFFF" Template="{DynamicResource GlassButton}">
    <Button.Effect>
        <DropShadowEffect Color="Gray" Opacity="0.5" ShadowDepth="6"/>
    </Button.Effect>
</Button>
...
Рейтинг: 0 / 0
14.10.2014, 16:22
    #38776391
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Помогите найти ошибку, необходимо по нажатию кнопки, чтобы она меня цвет наполовину, и цвет держался несколько секунд, у меня она просто меняет цвет
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
<Window x:Class="WpfApplication12.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
            <ControlTemplate x:Key="TemplateB" TargetType="Button">
            <Border BorderBrush="Orange" BorderThickness="3" CornerRadius="2" Name="bor"
                  TextBlock.Foreground="Red">
                <Border.Background>
                    <LinearGradientBrush>
                        <GradientStopCollection>
                            <GradientStop Offset="0" Color="Yellow"></GradientStop>
                            <GradientStop Offset="1" Color="Green"></GradientStop>
                        </GradientStopCollection>
                    </LinearGradientBrush>
                </Border.Background>
                <ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}"></ContentPresenter>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="bor" Property="Background" Value="Green"></Setter>
                </Trigger>
                <!--Trigger Property="IsPressed" Value="True">
                    <Setter TargetName="bor" Property="Background" Value="Red"></Setter>
                </Trigger-->
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <ControlTemplate x:Key="TemplateA" TargetType="Button">
            <Border Name="bor"
                  TextBlock.Foreground="Red">
                <Border.Background>
                    <LinearGradientBrush>
                        <GradientStopCollection>
                            <GradientStop Offset="0" Color="Yellow"></GradientStop>
                            <GradientStop Offset="1" Color="Green"></GradientStop>
                        </GradientStopCollection>
                    </LinearGradientBrush>
                </Border.Background>
                <ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}"></ContentPresenter>
                <Border.Triggers>
                    <EventTrigger RoutedEvent="Border.MouseDown">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)">
                                        <LinearColorKeyFrame KeyTime="00:00:00" Value="Red"></LinearColorKeyFrame>
                                    </ColorAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                </Border.Triggers>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="bor" Property="Background" Value="Green"></Setter>
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="bor"  Property="Background" Value="Red"></Setter>
                </Trigger>
            </ControlTemplate.Triggers>
            </ControlTemplate>
    </Window.Resources>
    <Button Margin="10" Width="130" Height="130" Template="{StaticResource TemplateB}">
    <Button Margin="65,0,0,0" Width="65" Height="130" Template="{StaticResource TemplateA}"></Button>
    </Button>
</Window>
...
Рейтинг: 0 / 0
14.10.2014, 16:38
    #38776417
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
честно сказать вы какую то лабуду написали, кнопка в кнопка...
используйте VisualStateManager и не будет у вас проблем. Там можно и задержки между переходами в другие состояния сделать и анимацию прикрутить при которой кнопка будет менять цвет так как вам душе угодно
...
Рейтинг: 0 / 0
15.10.2014, 11:45
    #38777101
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Как можно сделать, чтобы после нажатия, кнопка была зеленой несколько секунд?
И как можно чтобы при наведении/нажатии кнопка меняла цвет на половину желтый/зеленый?
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
<Window x:Class="WpfApplication13.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="a"  TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Border CornerRadius="3">
                                <Border.Background>
                                    <SolidColorBrush x:Name="BackgroundColor" Color="Red"/>
                                </Border.Background>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Border>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates" >
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition To="MousePressed" GeneratedDuration="0:0:5"/>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" 
                                                            To="Yellow" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" 
                                                            To="ForestGreen" Duration="0:0:0.5"></ColorAnimation>
                                     </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused"/>
                                    <VisualState x:Name="Unfocused" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Button Margin="10" Width="190" Height="190" Style="{StaticResource a}"></Button>
</Window>
...
Рейтинг: 0 / 0
15.10.2014, 13:38
    #38777307
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Slant-shadow,

Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
    class ButtonEx : Button
    {
        private bool _clicked;
        private readonly DispatcherTimer _timer;

        public ButtonEx()
        {
            _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) };
            _timer.Tick += timer_Tick;
            ChangeState();
        }
        protected override void OnClick()
        {
            base.OnClick();
            _clicked = true;
            ChangeState();
        }
        void timer_Tick(object sender, EventArgs e)
        {
            _clicked = false;
            _timer.Stop();
            ChangeState();
        }
        protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            ChangeState();
        }
        protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
        {
            base.OnMouseEnter(e);
            ChangeState();
        }
        private void ChangeState()
        {
            if (_clicked) 
            {
                VisualStateManager.GoToState(this, "Clicked", true);
                _timer.Start();
            }
            else 
            {
                VisualStateManager.GoToState(this, IsMouseOver ? "Over" : "NormalEx", true);
            }
        }
    }



Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
    <Window.Resources>
        <Style x:Key="a"  TargetType="{x:Type myApp:ButtonEx}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type myApp:ButtonEx}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="1*"/>
                                <RowDefinition Height="1*"/>
                            </Grid.RowDefinitions>
                            
                            <Border Grid.Row="0"  CornerRadius="3,3,0,0">
                                <Border.Background>
                                    <SolidColorBrush x:Name="BackgroundColor1" Color="Red"/>
                                </Border.Background>
                            </Border>
                            <Border Grid.Row="1"  CornerRadius="0,0,3,3">
                                <Border.Background>
                                    <SolidColorBrush x:Name="BackgroundColor2" Color="Red"/>
                                </Border.Background>
                            </Border>
                            
                            <ContentPresenter Grid.Row="0" Grid.RowSpan="2" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="NormalEx">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor1" Storyboard.TargetProperty="Color" 
                                                            To="Red" Duration="0:0:0.5" />
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor2" Storyboard.TargetProperty="Color" 
                                                            To="Red" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Clicked">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor1" Storyboard.TargetProperty="Color" 
                                                            To="ForestGreen" Duration="0:0:0.5"/>
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor2" Storyboard.TargetProperty="Color" 
                                                            To="Red" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Over" >
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor1" Storyboard.TargetProperty="Color" 
                                                            To="Red" Duration="0:0:0.5" />
                                            <ColorAnimation Storyboard.TargetName="BackgroundColor2" Storyboard.TargetProperty="Color" 
                                                            To="Yellow" Duration="0:0:0.5" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed"/>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused"/>
                                    <VisualState x:Name="Unfocused" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <myApp:ButtonEx Margin="10" Width="190" Height="190" Style="{StaticResource a}">
            <TextBlock FontSize="30" Text="Button1"/>
        </myApp:ButtonEx>
    </Grid>
...
Рейтинг: 0 / 0
16.10.2014, 01:27
    #38778086
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Roman Mejtes, А можно как-нибудь все сделать не используя C#?
...
Рейтинг: 0 / 0
16.10.2014, 11:42
    #38778347
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Slant-shadow,

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
    <Window.Resources>
        <Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="1*"/>
                                <RowDefinition Height="1*"/>
                            </Grid.RowDefinitions>

                            <Border Grid.Row="0"  CornerRadius="3,3,0,0">
                                <Border.Background>
                                    <SolidColorBrush x:Name="BackgroundColor1" Color="Red"/>
                                </Border.Background>
                            </Border>
                            <Border Grid.Row="1"  CornerRadius="0,0,3,3">
                                <Border.Background>
                                    <SolidColorBrush x:Name="BackgroundColor2" Color="Red"/>
                                </Border.Background>
                            </Border>
                            <ContentPresenter Grid.Row="0" Grid.RowSpan="2" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="BackgroundColor2">
                                            <ColorAnimation  Storyboard.TargetProperty="Color"
                                                     Duration="0:0:1" To="Yellow"  />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                                <Trigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="BackgroundColor2">
                                            <ColorAnimation  Storyboard.TargetProperty="Color"
                                                     Duration="0:0:1" To="Red"  FillBehavior="Stop" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.ExitActions>
                            </Trigger>

                            <Trigger Property="IsPressed" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="BackgroundColor1">
                                            <TimelineCollection >
                                                <ColorAnimation Storyboard.TargetProperty="Color" 
                                                            BeginTime="0:0:0" Duration="0:0:1" 
                                                            To="Green" FillBehavior="Stop" />
                                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color"
                                                                          BeginTime="0:0:1" Duration="0:0:4"
                                                                          FillBehavior="Stop">
                                                    <DiscreteColorKeyFrame KeyTime="0:0:0" Value="Green"/>
                                                </ColorAnimationUsingKeyFrames>
                                            </TimelineCollection>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Button Content ="test" Width="100" Height="30" Style="{StaticResource MyButtonStyle}">

    </Button>
...
Рейтинг: 0 / 0
16.10.2014, 11:54
    #38778377
Roman Mejtes
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Roman Mejtes,

можно проще, поторопился

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
                            <Trigger Property="IsPressed" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="BackgroundColor1">
                                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color"
                                                                          BeginTime="0:0:0" Duration="0:0:4"
                                                                          FillBehavior="Stop">
                                                <SplineColorKeyFrame KeyTime="0:0:1" Value="Green"/>
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            </Trigger>
...
Рейтинг: 0 / 0
17.10.2014, 08:01
    #38779331
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Roman Mejtes, Большое спасибо
...
Рейтинг: 0 / 0
21.10.2014, 14:20
    #38782899
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
А можно еще чтобы вместо кнопки использовать эллипс?
...
Рейтинг: 0 / 0
21.10.2014, 14:26
    #38782911
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Только полностью закрашивается при нажатии а не наполовину
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
<Window x:Class="WpfApplication17.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="Button" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="190"></RowDefinition>
                                <RowDefinition Height="190"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Ellipse Grid.Column="0">
                                <Ellipse.Fill>
                                    <SolidColorBrush x:Name="ColorLeft" Color="Red"></SolidColorBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <Ellipse Grid.Column="1">
                                <Ellipse.Fill>
                                    <SolidColorBrush x:Name="ColorRight" Color="Red"></SolidColorBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <ContentPresenter Grid.Row="0" Grid.RowSpan="2"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding  VerticalContentAlignment}"></ContentPresenter>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="ColorLeft">
                                            <ColorAnimation  Storyboard.TargetProperty="Color" Duration="0:0:1" To="Yellow">
                                            </ColorAnimation>
                                        </Storyboard>
                                    </BeginStoryboard>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="ColorRight">
                                            <ColorAnimation  Storyboard.TargetProperty="Color" Duration="0:0:1" To="Yellow">
                                            </ColorAnimation>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                                <Trigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="ColorLeft">
                                            <ColorAnimation  Storyboard.TargetProperty="Color"
                                                     Duration="0:0:1" To="Red"  FillBehavior="Stop"></ColorAnimation>
                                        </Storyboard>
                                    </BeginStoryboard>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="ColorRight">
                                            <ColorAnimation  Storyboard.TargetProperty="Color"
                                                     Duration="0:0:1" To="Red"  FillBehavior="Stop"></ColorAnimation>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.ExitActions>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard TargetName="ColorRight">
                                            <TimelineCollection>
                                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color"
                                                                          BeginTime="0:0:1" Duration="0:0:5"
                                                                          FillBehavior="Stop">
                                                    <DiscreteColorKeyFrame KeyTime="0:0:0" Value="Green"></DiscreteColorKeyFrame>
                                                </ColorAnimationUsingKeyFrames>
                                            </TimelineCollection>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Button  Width="190" Height="190" Style="{StaticResource Button}"></Button>
</Window>
...
Рейтинг: 0 / 0
21.10.2014, 16:44
    #38783213
Slant-shadow
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Изменение кнопки
Настроил Margin, все получилось
...
Рейтинг: 0 / 0
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Изменение кнопки / 18 сообщений из 18, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]