powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / помогите найти косяки в стиле UserControla
1 сообщений из 1, страница 1 из 1
помогите найти косяки в стиле UserControla
    #38464380
4eburawka
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
День добрый. Была у меня нормальная ТогглеКнопка. Стиль у нее менялся так как я хотел. Но потребовалось на кнопке отобразить некоторую дополнительную информацию. Сделал UserControl. И уже второй день не могу его заставить работать так как мне нужно. Помогите Христа ради люди добрые. Моя кнопка обладает рядом ошибок которые у меня не получается исправить:
1. Должна занимать все свободное пространство, а не как сейчас, только в центре.
2. Стиль реагирует на свойство Type, но не реагирует на IsCheked.
3. Применяя стиль, у меня меняется цвет вокруг кнопки, а не цвет самой кнопки.
Легче всего понять что не так это посмотреть как это выглядит. Я сделал и прицепил тестовый проект с этой кнопкой. Помогите пожалуйста сдвинуться с мертвой точки!

Код: 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.
<UserControl x:Class="RP.ChartButton"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:rp="clr-namespace:RP"
            x:Name="parent" Margin="0" MinHeight="26" MinWidth="26">
    <UserControl.Resources>
        <rp:MathConverter x:Key="MathConverter"/>

    </UserControl.Resources>
    <Grid>
        <ToggleButton x:Name="ToggleButton" DataContext="{Binding ElementName=parent}" 
            ClickMode="Press" BorderThickness="0" Background="White" Padding="0">
            <Grid>
                <Border CornerRadius="2" BorderThickness="1" BorderBrush="Gray" />
                <Border CornerRadius="0,2,0,6" BorderThickness="1" Background="Red" BorderBrush="Gray"
                    Width="7" Height="7" VerticalAlignment="Top" HorizontalAlignment="Right" />
                <Label x:Name="Label" Margin="-1,0,-1,2" Content="XXX" HorizontalAlignment="Center"/>
                <Border CornerRadius="2,2,2,2" Margin="2" BorderThickness="1"
                    Background="#00FF0E" BorderBrush="Gray" Height="4"
                    VerticalAlignment="Bottom" HorizontalAlignment="Left">
                    <Border.Width>
                        <MultiBinding Converter="{StaticResource MathConverter}" ConverterParameter="x*(y-8)+4">
                            <Binding Path="Fraction" />
                            <Binding Path="ActualWidth" />
                        </MultiBinding>
                    </Border.Width>
                </Border>
            </Grid>
        </ToggleButton>
    </Grid>
</UserControl>



Код: 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="ChartButtonStyle" TargetType="{x:Type rp:ChartButton}">
            <Setter Property="Background" Value="White"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type rp:ChartButton}">
                        <Grid x:Name="grid">
                            <Border x:Name="border" CornerRadius="2" BorderBrush="Black"
                                    BorderThickness="0"
                                    Margin="1"
                                    Padding="1"
                                    Background="{TemplateBinding Background}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="Type" Value="Liaw">
                                <Setter Property="Background" Value="PaleTurquoise"/>
                                <Setter Property="Foreground" Value="Gray" />
                            </Trigger>
                            <Trigger Property="Type" Value="Miaw">
                                <Setter Property="Background" Value="LightYellow"/>
                                <Setter Property="Foreground" Value="Gray" />
                            </Trigger>
                            <Trigger Property="Type" Value="Kriu">
                                <Setter Property="Background" Value="#FFFFDCDC"/>
                                <Setter Property="Foreground" Value="Gray" />
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsChecked" Value="True" />
                                    <Condition Property="Type" Value="Liaw" />
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter Property="Background" Value="DodgerBlue" />
                                    <Setter Property="Foreground" Value="White" />
                                </MultiTrigger.Setters>
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsChecked" Value="True" />
                                    <Condition Property="Type" Value="Miaw" />
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter Property="Background" Value="#FFFFD720" />
                                    <Setter Property="Foreground" Value="Black" />
                                </MultiTrigger.Setters>
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsChecked" Value="True" />
                                    <Condition Property="Type" Value="Kriu" />
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter Property="Background" Value="#FFFF2020" />
                                    <Setter Property="Foreground" Value="White" />
                                </MultiTrigger.Setters>
                            </MultiTrigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="BorderThickness" TargetName="border" Value="1"/>
                                <Setter Property="Padding" TargetName="border" Value="0"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Grid>
        <rp:ChartButton />
    </Grid>



Код: 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.
47.
48.
49.
50.
51.
52.
53.
using System;
using System.Windows;

namespace RP
{
    /// <summary>
    /// Interaction logic for ChartButton.xaml
    /// </summary>
    public partial class ChartButton
    {
        public enum ButtonType
        {
            Unknown = 0,
            Liaw = 6,
            Miaw = 4,
            Kriu = 12
        }

        #region public HandType Type DP
        public ButtonType Type
        {
            get { return (ButtonType)GetValue(ButtonTypeProperty); }
            set { SetValue(ButtonTypeProperty, value); }
        }
        public static readonly DependencyProperty ButtonTypeProperty = DependencyProperty.Register("Type", typeof(ButtonType), typeof(ChartButton));
        
        #endregion

        #region public Double Fraction DP
        public Double Fraction
        {
            get { return (Double)GetValue(ButtonFractionProperty); }
            set { SetValue(ButtonFractionProperty, value); }
        }
        public static readonly DependencyProperty ButtonFractionProperty = DependencyProperty.Register("Fraction", typeof(Double), typeof(ChartButton));
        
        #endregion

        #region public Boolean? IsChecked DP
        public Boolean? IsChecked
        {
            get { return ToggleButton.IsChecked; }
            set { ToggleButton.IsChecked = value; }
        }
        public static readonly DependencyProperty ButtonIsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(Boolean?), typeof(ChartButton));
        #endregion

        public ChartButton()
        {
            InitializeComponent();
        }
    }
}
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / помогите найти косяки в стиле UserControla
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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